ios webView 同时添加单击和长按手势

来源:互联网 发布:软件开发简历 编辑:程序博客网 时间:2024/06/05 05:27

添加手势代码:

 // 单击的 Recognizer    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapToDo)];    tap.delegate = self;    [theWebView addGestureRecognizer:tap];    //长按    UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo)];    longPressGr.minimumPressDuration = 1.0;    longPressGr.delegate = self;    [theWebView addGestureRecognizer:longPressGr];    // 如果长按确定偵測失败才會触发单击    [tap requireGestureRecognizerToFail:longPressGr];

webView添加tap手势无效果
webView中已经内部集成了点击、滑动等手势,当我们自己新建了一个tap手势,设置代理,添加手势后,仍需要实现允许多个手势并发的代理方法,代码如下:

// 允许多个手势并发- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {    return YES;}
0 0
原创粉丝点击