2

我需要一些帮助,我真的需要知道在我执行一些程序生成的滚动后会调用什么 UIScrollView 委托方法。从这个链接,我知道我必须尝试实施

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

但是在我实现它之后,从 NSlog,我知道当滚动视图已经完成时没有调用这个方法,nslog 显示在调用这个委托方法之后,应用程序调用了

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

然后再次调用scrollViewDidEndScrollingAnimation,多次返回scrollViewDidScroll,直到滚动真正停止,我需要在程序生成滚动之前将BOOL值设置为True,并且需要在滚动真正停止后将其设置为False。有人可以帮我解决这个问题吗?

这是我的示例代码,要做到这一点:

BOOL isScroll;

- (void)viewDidLoad {
    isScroll = YES;
    [self generateScrollProgrammatically];
}

- (void) generateScrollProgrammatically{
    //i do some code for scrolling uiscrollview programmatically
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"scrollViewDidScroll");

    if (isScroll){
        //do something
    }

}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
    NSLog(@"scrollViewDidEndScrollingAnimation");
}

这是我被告知的nslog:

2012-05-31 09:58:10.583 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.584 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.595 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.596 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.597 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.598 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.611 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.615 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.616 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.617 myApps[1203:fb03] scrollViewDidEndScrollingAnimation
2012-05-31 09:58:10.631 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.632 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.633 myApps[1203:fb03] scrollViewDidEndScrollingAnimation
2012-05-31 09:58:10.634 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.635 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.636 myApps[1203:fb03] scrollViewDidEndScrollingAnimation
2012-05-31 09:58:10.636 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.637 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.638 myApps[1203:fb03] scrollViewDidEndScrollingAnimation
2012-05-31 09:58:10.640 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.642 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.644 myApps[1203:fb03] scrollViewDidEndScrollingAnimation
2012-05-31 09:58:10.644 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.645 myApps[1203:fb03] scrollViewDidScroll
2012-05-31 09:58:10.646 myApps[1203:fb03] scrollViewDidEndScrollingAnimation
4

1 回答 1

1

是的,这也咬到我了。我能找到的唯一方法是替换:

[scrollView setContentOffset:offset animated:YES];

和:

[UIView animateWithDuration:[[UIApplication sharedApplication] statusBarAnimationDuration]
                 animations:^{ scrollView.contentOffset = offset; }
                 completion:^{ [scrollView.delegate scrollViewDidEndScrollingAnimation:scrollView]; }];
于 2012-05-31T20:06:07.660 回答