Setting contentOffset programmatically triggers scrollViewDidScroll

前端 未结 6 1299
别跟我提以往
别跟我提以往 2020-12-04 09:02

I\'ve got a a few UIScrollView on a page. You can scroll them independently or lock them together and scroll them as one. The problem occurs when they are locke

6条回答
  •  眼角桃花
    2020-12-04 09:38

    This is not a direct answer to the question, but if you are getting what appear to be spurious such messages, it can ALSO be because you are changing the bounds. I am using some Apple sample code with a "tilePages" method that removes and adds subview to a scrollview. This infrequently results in additional scrollViewDidScroll: messages called immediately, so you get into a recursion which you for sure didn't expect. In my case I got a nasty impossible to find crash.

    What I ended up doing was queuing the call on the main queue:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if(scrollView == yourScrollView) {
            // dispatch fixes some recursive call to scrollViewDidScroll in tilePages (related to removeFromSuperView)
            // The reason can be found here: http://stackoverflow.com/questions/9418311
            dispatch_async(dispatch_get_main_queue(), ^{ [self tilePages]; });
        }
    }
    

提交回复
热议问题