欢迎来到入门教程网!

Swift

当前位置:主页 > 软件编程 > Swift >

Swift中添加双击手势识别器

来源:本站原创|时间:2020-01-11|栏目:Swift|点击:

已经完成了单击识别器,但无法弄清楚如何将该单击识别器改为双击.

代码:

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

下一篇:Swift解决UITableView空数据视图问题的简单方法

本文标题:Swift中添加双击手势识别器

本文地址:https://www.xiuzhanwang.com/a1/Swift/11922.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有