UIPanGestureRecognizer有时无法在iOS 7上运行 [英] UIPanGestureRecognizer sometimes not working on iOS 7
问题描述
我收到来自iOS 7用户的间歇性报告,称 UIPanGestureRecognizer
每隔一段时间停止处理某些视图。他们应该能够向右/向左滑动视图,但它只是因为某种未知原因而中断并且不起作用。强制退出应用程序并重新启动它可以解决问题。
I'm getting intermittent reports from users on iOS 7 saying that the UIPanGestureRecognizer
stops working on certain views every once in a while. They're supposed to be able to swipe a view to the right/left, but it just breaks and doesn't work for some unknown reason. Force quitting the app and relaunching it fixes the problem.
这个问题在iOS 6上从未发生过。除了 gestureRecognizerShouldBegin之外,我没有任何禁用手势识别器的代码
委托强制手势仅识别水平平底锅:
This problem never happened on iOS 6. And I don't have any code that disables the gesture recognizer at any time besides the gestureRecognizerShouldBegin
delegate that forces the gesture to only recognize horizontal pans:
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isMemberOfClass:[UIPanGestureRecognizer class]]) {
CGPoint translation = [gestureRecognizer translationInView:[self superview]];
if (fabsf(translation.x) > fabsf(translation.y)) {
if (translation.x > 0)
return YES;
}
}
return NO;
}
UIPanGestureRecognizer $ c中有任何变化可能导致此问题的$ c>(或只是简单的
UIGestureRecognizer
)?
推荐答案
我想我终于解决了这个问题。显然,iOS 7处理子视图中的手势与iOS 6及更早版本中的手势不同。为了解决这个问题,Apple实施了一个新的委托:
I think I finally solved this issue. Apparently iOS 7 handles gestures in subviews differently than it did in iOS 6 and earlier. To handle this, Apple implemented a new delegate:
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
如果您返回YES,那么应该让您的手势识别器工作。我已经实现了它并且到目前为止没有任何问题(尽管这是一个罕见的错误,我永远无法可靠地重现,所以它可能还没有复发)。
If you return YES, that should get your gesture recognizer to work. I've implemented it and haven't had any issues so far (though admittedly this was a rare bug that I could never reliably reproduce, so it's possible that it just hasn't recurred yet).
有关详细信息,请参阅
https://stackoverflow.com/a/19892166/1593765 。
For more information, see https://stackoverflow.com/a/19892166/1593765.
这篇关于UIPanGestureRecognizer有时无法在iOS 7上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!