简体   繁体   中英

UIScrollView UIPangestureRecognizer dead zone on top edge of screen

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!

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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM