概述
已经完成了单击识别器,但无法弄清楚如何将该单击识别器改为双击.
代码:
import Foundation import UIKit class MainBoardController: UIViewController{ let tap = UITapGestureRecognizer() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. var swipe: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self,action: "GotoProfile") swipe.direction = UISwipeGestureRecognizerDirection.Right self.view.addGestureRecognizer(swipe) tap.addTarget(self,action: "GotoCamera") view.userInteractionEnabled = true view.addGestureRecognizer(tap) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func GotoProfile(){ self.performSegueWithIdentifier("Profilesegue",sender: nil) } func GotoCamera(){ self.performSegueWithIdentifier("Camerasegue",sender: nil) } }
解决方法
最终用扩展解决了这个问题:
override func viewDidLoad() { super.viewDidLoad() let tapGR = UITapGestureRecognizer(target: self,action: #selector(PostlistViewController.handleTap(_:))) tapGR.delegate = self tapGR.numberOfTapsRequired = 2 view.addGestureRecognizer(tapGR) } extension MainBoardController: UIGestureRecognizerDelegate { func handleTap(_ gesture: UITapGestureRecognizer){ print("doubletapped") } }
总结
以上是靠谱客为你收集整理的如何在Swift中添加双击手势识别器全部内容,希望文章能够帮你解决如何在Swift中添加双击手势识别器所遇到的程序开发问题。
最后
以上就是认真睫毛为你收集整理的Swift中添加双击手势识别器的全部内容,希望文章能够帮你解决Swift中添加双击手势识别器所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复