0

如下图所示,当在屏幕顶部的“死区”内开始拖动时,UIPanGestureRecognizer 不会平移。这很可能是通知中心造成的。

在此处输入图像描述

但是 touchesMoved:withEvent: 方法确实会被调用,因此应该有一种方法可以在该区域中识别平移手势。

有没有其他人遇到过这个问题,是否有任何解决方法?谢谢你的帮助!

4

2 回答 2

0

屏幕顶部边缘可能有多个干扰手势识别器。可能是系统添加了另一个干扰的手势识别器,带有一些 UIElement。

尝试在您的手势识别器委托上实现UIGestureRecognizerDelegate 。

特别是这种方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{

     NSLog(@"1st recognizer class: %@ ; 2nd recognizer class: %@", NSStringFromClass([gestureRecognizer class]), NSStringFromClass([otherGestureRecognizer class])); 

     return YES; 

}

https://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIGestureRecognizerDelegate/gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer

于 2013-10-21T13:33:17.033 回答
0

解决了这个问题。touchesMoved:withEvent: 应该这样实现:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches.allObjects objectAtIndex:0];
    CGPoint location = [touch locationInView:self];
    CGPoint previousLocation = [touch previousLocationInView:self];
    CGPoint contentOffset = self.contentOffset;

    contentOffset.x -= location.x - previousLocation.x;
    [self setContentOffset:contentOffset animated:NO];
}
于 2013-10-21T19:15:36.053 回答