我正试图检测继续拖过屏幕底部。我尝试使用UIPanGestureRecognizer,但是一旦手指到达屏幕边缘,它就会停止触发,除了在顶部。现在我正在尝试使用UIScreenEdgePanGestureRecognizer,但是虽然gestureRecognizer委托方法应该触发,但是手势本身的指定选择器永远不会触发。任何帮助将不胜感激。
此代码位于viewDidLoad:
中UIScreenEdgePanGestureRecognizer *selectScreenEdgeDrag = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgeSelect:)];
[selectScreenEdgeDrag setEdges:UIRectEdgeBottom];
selectScreenEdgeDrag.delegate = self;
[self.view addGestureRecognizer:selectScreenEdgeDrag];
委托方法:
- (void)screenEdgeSelect:(UIScreenEdgePanGestureRecognizer *)gesture {
NSLog(@"screenEdgeSelect");
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
NSLog(@"shouldRecognizeSimultaneouslyWithGestureRecognizer");
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press {
NSLog(@"shouldReceivePress");
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch {
NSLog(@"shouldReceiveTouch");
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return NO;
}
我做错了什么?
感谢。
答案 0 :(得分:0)
它永远不会触发,因为您将edges
属性设置为UIRectEdgeBottom
并且它与系统控制中心发生冲突。每当我尝试从底部边缘滑动时,控制中心就会显示出来。如果您将edges
设置为UIRectEdgeLeft
或UIRectEdgeRight
,一切都会正常运行。
如果你仍然需要使用底边手势,那么你有选择(据我所知):
UIStatusBar
):在这种情况下,您的代码将按预期工作。状态栏隐藏后,控制中心不会自动显示。相反,小箭头将显示在底部边缘,使用户可以根据需要打开设置。但根据Apple's guidelines:在永久隐藏状态栏之前请三思。
希望这些信息有用。