【发布时间】:2015-05-02 10:27:04
【问题描述】:
我在 ContainerView 和 UITextView 中创建了一个 UIScrollView 作为 UIScrollView 的子视图。我初始化 textView 并将 scrollEnabled 设置为 true。现在基于 scrollView 的 contentOffset.y,我想继续在 textView 上切换 scrollEnabled。但是由于某种原因,一旦我将 scrollEnabled 设置为 false,我似乎无法再次启用滚动...
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不能再增长,所以第一个条件不能再满足。为什么要禁用/启用滚动?也许您的问题还有其他解决方案。 -
我在 textView 而不是 scrollView 上禁用滚动。所以 contentOffset 不是问题......我在屏幕的一半左右有一个菜单(UIButtons)。当用户开始滚动时,用户应该能够将菜单滚动到顶部,然后 textView 才开始滚动。
-
您能否在
scrollViewDidScroll方法中添加一些日志记录,以查看 contentOffset 是什么,如果它达到 180?或者只是在if中添加一个断点,以查看是否满足条件。可能scrollView的contentSize不大于180? -
它确实很满意...但是一旦我将 textView.scrollEnabled 设置为 false,它就不想再滚动了
标签: ios swift uiscrollview uitextview