I have created a UIScrollView in a ContainerView and a UITextView as a subview of UIScrollView. I initialize the textView with scrollEnabled set to true. Now based on the contentOffset.y of the scrollView, I want to keep toggling scrollEnabled on the textView. But for some reason, once I set scrollEnabled to false, I can't seem to enable scroll again...
override func viewDidload() {
self.scrollView = UIScrollView(frame: CGRectMake(...))
self.scrollView.delegate = self
self.view.addSubview(self.scrollView)
self.textView = UITextView(frame: CGRectMake(...))
self.textView.scrollEnabled = true
self.textView.userInteractionEnabled = true
self.scrollView.addSubview(self.textView)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
if self.scrollView.contentOffset.y >= 180 {
self.textView.scrollEnabled = true // This does not work!
} else {
self.textView.scrollEnabled = false // This works!
}
}
contentOffset
cannot grow anymore, so the first condition can't be satisfied anymore. Why do you want to disable/enable the scrolling? Maybe there is another solution to your problem than this. – Catalina T.scrollViewDidScroll
method to see what the contentOffset is, if it ever gets to be 180? Or just add a breakpoint in theif
, to see if the condition is ever satisfied. Maybe thecontentSize
of the scrollView is not bigger than 180? – Catalina T.