问题
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