在编程生成的滚动完成后将调用的UIScrollview委托方法

时间:2012-05-31 03:00:27

标签: ios5 uiscrollview scroll uiscrollviewdelegate

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

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

但是在我实现它之后,从NSlog,我知道当scrollview已经完成时这个方法没有调用,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

1 个答案:

答案 0 :(得分:1)

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

[scrollView setContentOffset:offset animated:YES];

使用:

[UIView animateWithDuration:[[UIApplication sharedApplication] statusBarAnimationDuration]
                 animations:^{ scrollView.contentOffset = offset; }
                 completion:^{ [scrollView.delegate scrollViewDidEndScrollingAnimation:scrollView]; }];