2
votes

i need some help, i really need to know what UIScrollView delegate method that will called after i do some programmatic-generated scroll. From this link, i know that I have to try to implement

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

but after i implement it, from NSlog, i know that this method did not called when the scrollview already finish, the nslog show that after called this delegate method, the app called

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

and then called scrollViewDidEndScrollingAnimation again, back to scrollViewDidScroll in many times, until the scroll really stop, i need to set a BOOL value into True before do programmatic-generated scroll, and need to False it after the scroll really stop. Can somebody help me to figure out this problem?

this is my sample code, to do this :

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");
}

here the nslog that i was told :

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
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView use this delegate methodTirth
@iHungry it's not working, because i generate the scroll programmatically, without touch it scrollviewR. Dewi

1 Answers

1
votes

Yeah, this bit me too. The only way I could find around it is to replace:

[scrollView setContentOffset:offset animated:YES];

with:

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