屏幕顶部的UIScrollView UIPangestureRecognizer死区

时间:2013-10-21 13:24:43

标签: ios uiscrollview screen uipangesturerecognizer edge

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

enter image description here

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

有没有其他人遇到过这个问题,那里有没有相关的解决方法?谢谢你的帮助!

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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];
}