scrollViewDidScroll delegate is invoking automatically
Asked Answered
A

5

11

I am using scrollViewDidScroll delegate in my application.

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.

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?

Adviser answered 25/7, 2012 at 18:16 Comment(0)
A
5

scrollViewDidScroll also gets invoked when the orientation changes. This I came to know from here. This was the problem I was facing. And now my problem solved with this post.

Adviser answered 27/7, 2012 at 19:4 Comment(0)
G
10

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.

- (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;
} 
Gallo answered 5/1, 2015 at 16:55 Comment(0)
S
5

relevant

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.

Surakarta answered 25/7, 2012 at 18:22 Comment(0)
A
5

scrollViewDidScroll also gets invoked when the orientation changes. This I came to know from here. This was the problem I was facing. And now my problem solved with this post.

Adviser answered 27/7, 2012 at 19:4 Comment(0)
Q
4

If you want to know if scrollDidScroll was triggered manually (through finger gesters) or due to other events like didSelect or setContentOffset, use the UIScrollView.isTracking and UIScrollView.isDecelerating properties.

Example usage:

if scrollView.isTracking || scrollView.isDecelerating {
    scrollPosition = collectionView.contentOffset
}
Quartis answered 6/12, 2018 at 17:57 Comment(0)
R
1

Set UICollectionView, UITableView delegate here in this method

override func viewDidLayoutSubviews() {
     super.viewDidLayoutSubviews()
     // This method is called only after all subviews are laid
}
Rumilly answered 6/4, 2018 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.