在这次IOS应用开发教程中,我们打算实现手势识别。正如你所知道的,IOS支持大量的手势操作,它们能提供了很好的应用控制和出色用户体验。
已经完成了单击识别器,但无法弄清楚如何将该单击识别器改为双击.
代码:
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中添加双击手势识别器


基础教程推荐
猜你喜欢
- R语言因子型数值转数值型的操作 2022-11-23
- 如何将mysql数据库文件连接到Rails应用程序上的本地ruby 2023-09-21
- ruby – 如何使用Nginx,Passenger,Sinatra创建多个位置 2023-09-20
- 详解swift中xcworkspace多项目管理 2023-07-05
- 解决R语言中install_github中无法安装遇到的问题 2022-11-26
- 深入探究Golang中log标准库的使用 2023-07-25
- R语言的一个加法函数使用介绍 2022-11-14
- 汇编语言:比较指令、跳转指令、JCC的使用 2023-07-06
- R语言向量下标和子集的使用 2022-12-10
- R语言入门使用RStudio制作包含Rcpp代码的R包 2022-12-05