问题
我无法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
或 aUITapGestureRecognizer
我gesture handled
会在控制台中看到。我可以使用UIPanGestureRecognizer
只接受在屏幕边缘附近开始的手势。
猕猴桃键盘使用这样的解决方法。
警告:只有UIPanGestureRecognizer
当self.view
有背景颜色时才有效。