【问题标题】:UIScreenEdgePanGestureRecognizer doesn't work in a custom keyboard extensionUIScreenEdgePanGestureRecognizer 在自定义键盘扩展中不起作用
【发布时间】:2014-11-06 22:02:43
【问题描述】:

问题

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

示例

@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");
}

Download my example project on Github

可能的解决方法

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

Kiwi Keyboard 使用这样的解决方法。

警告:UIPanGestureRecognizer 仅在 self.view 具有背景颜色时才有效。

【问题讨论】:

    标签: ios ios8 uikit ios-app-extension ios-keyboard-extension


    【解决方案1】:

    据我所知,尽管名称为边,UIScreenEdgePanGestureRecognizeredges 必须设置为单边。 UIRectEdgeAll 不起作用,您必须为每个边创建一个 UIScreenEdgePanGestureRecognizer,您不能将边 OR 在一起。

    【讨论】:

    • 谢谢。不确定我是否曾经尝试过,但它现在有效。对于任何感兴趣的人,我已经更新了我的示例项目,使用从左右两侧进行的边缘滑动。 github.com/dmzza/ExampleKeyboard/commit/…
    • 天啊,非常感谢,你救了我一天!
    猜你喜欢
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 2015-10-22
    相关资源
    最近更新 更多