如何捕获 UIScrollView 或其他的取消调用?
有时,电话等中断会发生并扰乱 iPhone 或 iPad 中应用程序的正常行为。
例如,我创建了一个 UIScrollView 实例并实现了 UIScrollView 委托方法:scrollViewWillBeginDragging 和scrollViewDidEndDragging(以及scrollViewDidEndDecelerating)。
scrollViewWillBeginDragging 方法停用了我的应用程序中的所有自定义按钮。 然后scrollViewDidEndDragging 和scrollViewDidEndDecelerating 方法激活这些自定义按钮。也就是说,当用户滚动时,所有自定义按钮都会停用一段时间。
问题是,当用户 开始拖动并只是握住 UIScrollView 实例,如果我采取了 按主页按钮屏幕截图 和一个电源按钮,然后是以下任意一个 scrollViewDidEndDragging 和 scrollViewDidEndDecelerating 没有 接到电话。所以应用程序变得一团糟 向上。
我在 UIViewController 中实现了 UIApplicationWillResignActiveNotification 方法,但在截图后没有被调用。
如何捕获任何干扰常规事件流的中断?
有时,touchesEnd 和touchesCanceled 也不会因中断而被调用。
谢谢。
Sometimes, interruptions such as phone call occur and disturb a regular behavior of an app in iPhone or iPad.
For example, I created one UIScrollView instance and implemented UIScrollView delegate methods: scrollViewWillBeginDragging and scrollViewDidEndDragging(and scrollViewDidEndDecelerating).
A scrollViewWillBeginDragging method deactivated all custom buttons in my app.
Then scrollViewDidEndDragging and scrollViewDidEndDecelerating methods activated these custom buttons. That is, while the user scrolled, all custom buttons became deactivated for a while.
The problem was that while the user
started to drag and just held an
UIScrollView instance, if I took a
screenshot by pressing a home button
and a power button, then any of
scrollViewDidEndDragging and
scrollViewDidEndDecelerating didn't
get called. So the app became messed
up.
I implemented a UIApplicationWillResignActiveNotification method in my UIViewController, but it didn't get called after taking a screenshot.
How can I catch any kind of interruption that disturbs a regular flow of events?
Sometimes, touchesEnd and touchesCanceled didn't get called too due to an interruption.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,并通过使用 NSObject 的performSelector:withObject:afterDelay方法摆脱了它。
在scrollViewDidScroll:
您可以尝试这种技术并将其与您提到的其他技术结合起来。
希望这会有所帮助。祝你好运!
I faced the same problem and got rid of it by using
performSelector:withObject:afterDelay
method of NSObject.In scrollViewDidScroll:
You can try this technique and combine it with other that you mentioned.
Hope, that will help. Good luck!