Swift中添加雙擊手勢識別器
更新時間:2019年08月11日 15:26:53 投稿:hebedich
在這次IOS應(yīng)用開發(fā)教程中,我們打算實現(xiàn)手勢識別。正如你所知道的,IOS支持大量的手勢操作,它們能提供了很好的應(yīng)用控制和出色用戶體驗。
已經(jīng)完成了單擊識別器,但無法弄清楚如何將該單擊識別器改為雙擊.
代碼:
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")
}
}
總結(jié)
以上是腳本之家為你收集整理的如何在Swift中添加雙擊手勢識別器全部內(nèi)容,希望文章能夠幫你解決如何在Swift中添加雙擊手勢識別器所遇到的程序開發(fā)問題。
相關(guān)文章
Swift下使用UICollectionView 實現(xiàn)長按拖拽功能
拖拽排序是新聞類的App可以說是必有的交互設(shè)計,如今日頭條,網(wǎng)易新聞等。這篇文章主要介紹了Swift下使用UICollectionView 長按拖拽功能,需要的朋友可以參考下2017-03-03
Swift仿選擇電影票的效果并實現(xiàn)無限/自動輪播的方法
這篇文章主要給大家介紹了關(guān)于Swift仿選擇電影票的效果并實現(xiàn)無限/自動輪播的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-08-08
swift中利用runtime交換方法的實現(xiàn)示例
這篇文章主要給大家介紹了關(guān)于swift中利用runtime交換方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2018-05-05

