UIScrollView UIPangestureRecognizer dead zone on top edge of screen

好久不见. 提交于 2019-12-12 00:52:31

问题


as shown in the picture below the UIPanGestureRecognizer will not pan when the drag started inside the "dead zone" on the top of the screen. This is most likely caused by the notification center.

The touchesMoved:withEvent: method however does get called, so there should be a way to get pan gestures recognized in this area.

Has anyone else came across this issue, are there any workarounds out there yet? Thanks for any help!


回答1:


It is possible that on the top edge of the screen you have multiple gesture recognisers that interferes. It could be that the the other gesture recogniser that interferes is added by system with some UIElement.

Try to implement UIGestureRecognizerDelegate on your gesture recogniser delegate.

Especially this method:

- (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:




回答2:


Solved the problem. The touchesMoved:withEvent: should be implemented this way:

-(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];
}


来源:https://stackoverflow.com/questions/19495796/uiscrollview-uipangesturerecognizer-dead-zone-on-top-edge-of-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!