您的位置:首页 > 移动开发 > IOS开发

iOS开发中同时识别旋转与缩放手势

2015-11-21 18:34 411 查看
今天我在使用UIRotationGestureRecognizer和UIPinchGestureRecognizer时,发现它们在默认情况下不能同时被识别。而且在真机操作时,经常发生只识别缩放,难以识别旋转的情况。所以将它们设为能同时识别是非常有必要的。

经过调查,原来是要实现如下方法:

optional public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool


其实在方法体中return true就可以了。

UIRotationGestureRecognizer和UIPinchGestureRecognizer与该方法有什么关系?

UIRotationGestureRecognizer和UIPinchGestureRecognizer是UIGestureRecognizer的子类。UIGestureRecognizer的deleage的协议为UIGestureRecognizerDelegate。以上方法就是该协议中要遵循的方法。所以在实现以上方法时,不要忘记设置UIRotationGestureRecognizer和UIPinchGestureRecognizer的delegate。

此外还要说一下Simultaneous这个单词。初看,我还以为是模拟。但一查才知道,是“同时发生的”的意思。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS 手势 Gesture