3

问题

我无法UIScreenEdgePanGestureRecognizer在自定义键盘扩展中使用 a 来识别来自屏幕右侧或左侧边缘的边缘滑动。我创建了一个新项目来测试它。OtherUIGestureRecognizer的工作正常,如下所述。

例子

@implementation KeyboardViewController // A subclass of UIInputViewController
...
-(void)viewDidLoad {
  ...
  UIScreenEdgePanGestureRecognizer *gestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture)];
  [gestureRecognizer setEdges:UIRectEdgeAll];
  [self.view addGestureRecognizer:gestureRecognizer];
}

- (void)handleGesture
{
  NSLog(@"gesture handled");
}

在 Github 上下载我的示例项目

可能的解决方法

如果我将其更改为 aUIPanGestureRecognizer或 aUITapGestureRecognizergesture handled会在控制台中看到。我可以使用UIPanGestureRecognizer只接受在屏幕边缘附近开始的手势。

猕猴桃键盘使用这样的解决方法。

警告:只有UIPanGestureRecognizerself.view有背景颜色时才有效。

4

1 回答 1

10

As far as I know, despite the name edges, UIScreenEdgePanGestureRecognizer's edges must be set to a single edge. UIRectEdgeAll will not work, you have to create a UIScreenEdgePanGestureRecognizer for each edge, you can't OR edges together.

于 2014-11-22T04:31:11.767 回答