xcode scrollViewDidScroll 委托正在自动调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11656055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
scrollViewDidScroll delegate is invoking automatically
提问by Bharath
I am using scrollViewDidScroll delegate in my application.
我在我的应用程序中使用 scrollViewDidScroll 委托。
But, many times, even though I dint start scrolling, this delegate is getting invoked which is creating a lot of problem. I heard that even when contentSize for a particular scroll view is set then at that time also this delegate i.e., scrollViewDidScroll
will invoke.
但是,很多时候,即使我没有开始滚动,这个委托也会被调用,这造成了很多问题。我听说即使设置了特定滚动视图的 contentSize ,那时scrollViewDidScroll
也会调用这个委托。
What are the different scenarios in which this delegate gets invoked. What are the steps to control this?
调用此委托的不同场景有哪些。控制这种情况的步骤是什么?
Can I set any parameter to handle this?
我可以设置任何参数来处理这个问题吗?
采纳答案by Bharath
回答by Sev
To prevent scrollDidScroll:
from firing automatically when the view is loaded and adjusted, I waited to add my UIScrollView
delegate
until after all the views load using viewDidLayoutSubviews
. It is working well for me.
为了防止scrollDidScroll:
在加载和调整视图时自动触发,我等待添加我的,UIScrollView
delegate
直到使用viewDidLayoutSubviews
. 它对我来说效果很好。
- (void)viewDidLayoutSubviews {
// add table view delegate after the views have been laid out to prevent scrollViewDidScroll
// from firing automaticly when the view is adjusted on load, which makes the tab bar disappear
self.tableView.delegate = self;
}
回答by Dima
scrollViewDidScroll: gets called every time the scroll bounds change. This means it gets called during the scroll, as well as when it starts. You may want to try scrollViewWillBeginDragging: instead.
scrollViewDidScroll:每次滚动边界改变时都会被调用。这意味着它会在滚动期间以及开始时被调用。您可能想尝试使用 scrollViewWillBeginDragging: 代替。
回答by user1968991
Hi Guys its very old question, however, if you wanna know if the scrollDidScroll
was triggered manually(through finger) or its due to other event like didSelect
or setContentOffset
, use the UIScrollView.isTracking
property.
嗨,伙计们,这是一个非常古老的问题,但是,如果您想知道scrollDidScroll
是手动触发(通过手指)还是由于其他事件(如didSelect
or )setContentOffset
,请使用该UIScrollView.isTracking
属性。
回答by Karthik damodara
Set UICollectionView, UITableView delegate here in this method
在此方法中设置 UICollectionView、UITableView 委托
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// This method is called only after all subviews are laid
}