在程序生成的滚动完成后将调用啥 UIScrollview 委托方法
Posted
技术标签:
【中文标题】在程序生成的滚动完成后将调用啥 UIScrollview 委托方法【英文标题】:What UIScrollview delegate method that will called after programmatic-generated scroll finishes在程序生成的滚动完成后将调用什么 UIScrollview 委托方法 【发布时间】:2012-05-31 03:00:26 【问题描述】:我需要一些帮助,我真的需要知道在我执行一些程序生成的滚动之后会调用什么 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
【问题讨论】:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 使用这个委托方法 @iHungry 它不起作用,因为我以编程方式生成滚动,没有触摸它滚动视图 【参考方案1】:是的,这也咬了我一口。我能找到的唯一方法是替换:
[scrollView setContentOffset:offset animated:YES];
与:
[UIView animateWithDuration:[[UIApplication sharedApplication] statusBarAnimationDuration]
animations:^ scrollView.contentOffset = offset;
completion:^ [scrollView.delegate scrollViewDidEndScrollingAnimation:scrollView]; ];
【讨论】:
你用什么方法替换它? 无论您采用何种方法,您最初描述为“一些程序化生成的滚动”。上面的代码假设您使用的是 -setContentOffset:animated:。你不是吗? 不,我不使用它,但我想我知道我的代码有什么问题 :) 谢谢你的回答 :) @R.Dewi 请分享您认为的解决方案以上是关于在程序生成的滚动完成后将调用啥 UIScrollview 委托方法的主要内容,如果未能解决你的问题,请参考以下文章