如何在Swift中添加双击手势识别器
发布时间:2020-12-14 05:29:02 所属栏目:百科 来源:网络整理
导读:我已经完成了单击识别器,但无法弄清楚如何将该单击识别器改为双击.我可以使用一些指导. 码: import Foundationimport UIKitclass MainBoardController: UIViewController{ let tap = UITapGestureRecognizer() override func viewDidLoad() { super.viewDid
我已经完成了单击识别器,但无法弄清楚如何将该单击识别器改为双击.我可以使用一些指导.
码: 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") } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |