特定手势的同步手势识别 [英] Simultaneous gesture recognition for specific gestures

查看:35
本文介绍了特定手势的同步手势识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试启用同步手势识别,但仅适用于 UIPinchGestureRecognizerUIRotationGestureRecognizer 手势.我不希望它适用于任何其他手势.如果我将以下属性设置为 true,它允许同时识别所有手势,我如何将其限制为仅旋转和缩放?

I'm trying to enable simultaneous gesture recognition but only for the UIPinchGestureRecognizer and UIRotationGestureRecognizer gestures. I don't want it to work for any other gestures. If I set the following property to true it allows all gestures to be recognized simultaneously, how can I limit it to just rotating and scaling?

func gestureRecognizer(UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}

推荐答案

确保你的类实现了 UIGestureRecognizerDelegate

class YourViewController: UIViewController, UIGestureRecognizerDelegate ...

<小时>

设置手势的delegateself

yourGesture.delegate = self

<小时>

为类添加委托函数


Add delegate function to your class

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    if (gestureRecognizer is UIPanGestureRecognizer || gestureRecognizer is UIRotationGestureRecognizer) {
        return true
    } else {
        return false
    }
}

这篇关于特定手势的同步手势识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆