如何捕获 UIScrollView 或其他的取消调用?

发布于 2024-10-09 18:14:01 字数 747 浏览 3 评论 0原文

有时,电话等中断会发生并扰乱 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2024-10-16 18:14:01

我遇到了同样的问题,并通过使用 NSObject 的performSelector:withObject:afterDelay方法摆脱了它。

在scrollViewDidScroll:

[NSObject cancelPreviousPerformRequestsWithTarget:yourController];
[yourController deactivateButtons];
[yourController performSelector:@selector(activateButtons) withObject:nil afterDelay:0.5];

您可以尝试这种技术并将其与您提到的其他技术结合起来。
希望这会有所帮助。祝你好运!

I faced the same problem and got rid of it by using performSelector:withObject:afterDelay method of NSObject.

In scrollViewDidScroll:

[NSObject cancelPreviousPerformRequestsWithTarget:yourController];
[yourController deactivateButtons];
[yourController performSelector:@selector(activateButtons) withObject:nil afterDelay:0.5];

You can try this technique and combine it with other that you mentioned.
Hope, that will help. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文