UIScrollView 通知
我正在编写一个与 Apple 的 Weather.app 非常相似的应用程序:底部有一个 UIPageControl,屏幕中间有一个 UIScrollView。 在我的代码中,我实现了 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
方法来确定用户何时移动到新页面。如果他们移动到新页面,我会加载相邻页面的数据,以使进一步的页面切换更快。 (在 Apple 的一个示例中,使用了 - (void)scrollViewDidScroll:(UIScrollView *)sender
,但这会导致我的应用程序在加载新页面时短暂挂起,因此不合适。) 该代码运行得非常好。
我使用 scrollRectToVisible:
: 当用户单击 UIPageControl 时以编程方式在滚动视图内滚动。问题是,滚动完成后,scrollRectToVisible:
不会向 UIScrollViewDelegate 发送通知 - 因此,在使用 UIPageControl 时,永远不会调用负责加载相邻页面的代码。
有没有办法让 UIScrollView 在被 scrollRectToVisible:
方法调用时通知其委托?或者我是否必须使用线程来防止我的应用程序冻结?
谢谢!
——瑞
I'm coding an app that works much like Apple's Weather.app: There's a UIPageControl at the bottom and a UIScrollView in the middle of the screen.
In my code, I implemented the - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
method to figure out when the user did move to a new page. If they move to a new page, I load the adjacent pages' data, as to make further page-switching faster. (In one of Apple's examples, the - (void)scrollViewDidScroll:(UIScrollView *)sender
is used, but that causes my app to shortly hang when loading a new page, so it's not suitable.)
That code works very well.
I'm using scrollRectToVisible:
: to programmatically scroll inside the scrollview when the user clicks the UIPageControl. The problem is that the scrollRectToVisible:
doesn't post a notification to the UIScrollViewDelegate when it's done scrolling - so the code responsible for loading adjacent pages never get's called when using the UIPageControl.
Is there any way to make the UIScrollView notify its delegate when it gets called by the scrollRectToVisible:
method? Or will I have to use threads in order to prevent my app from freezing?
Thanks!
-- Ry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样
-scrollViewDidEndScrollingAnimation:
?如果不起作用,请尝试监听
UITextSelectionDidScroll
通知。 (当然,它没有文档记录。)或者,SDK 安全的方法是测量动画所需的时间,并在
-scrollRectToVisible:
的调用站点发送延迟通知。How about
-scrollViewDidEndScrollingAnimation:
?If it doesn't work, try to listen to the
UITextSelectionDidScroll
notification. (Of course, it's undocumented.)Alternatively, an SDK-safe method is measure the time taken for the animation and send a delayed notification at the call site of
-scrollRectToVisible:
.您可以添加此委托方法:
滚动视图在 UIScrollView 和 setContentOffset:animated: 和scrollRectToVisible:animated: 方法的实现结束时调用此方法,但前提是请求动画。
You could add this delegate method instead:
The scroll view calls this method at the end of its implementations of the UIScrollView and setContentOffset:animated: and scrollRectToVisible:animated: methods, but only if animations are requested.