UIScreenEdgePanGestureRecognizer永远不会触发操作

时间:2016-04-06 13:20:25

标签: ios uigesturerecognizer

我正试图检测继续拖过屏幕底部。我尝试使用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;
}

我做错了什么?

感谢。

1 个答案:

答案 0 :(得分:0)

它永远不会触发,因为您将edges属性设置为UIRectEdgeBottom并且它与系统控制中心发生冲突。每当我尝试从底部边缘滑动时,控制中心就会显示出来。如果您将edges设置为UIRectEdgeLeftUIRectEdgeRight,一切都会正常运行。

如果你仍然需要使用底边手势,那么你有选择(据我所知):

  • 您可以隐藏状态栏(UIStatusBar):在这种情况下,您的代码将按预期工作。状态栏隐藏后,控制中心不会自动显示。相反,小箭头将显示在底部边缘,使用户可以根据需要打开设置。但根据Apple's guidelines
  • ,您应该小心谨慎
  

在永久隐藏状态栏之前请三思。

  • 您可以要求用户在iOS设置中禁用控制中心。但是,我想,他们必须做出如此艰苦的工作才会生气:(

希望这些信息有用。