Swift中實(shí)現(xiàn)點(diǎn)擊、雙擊、捏、旋轉(zhuǎn)、拖動(dòng)、劃動(dòng)、長(zhǎng)按手勢(shì)的類(lèi)和方法介紹
1.UITapGestureRecognizer 點(diǎn)擊/雙擊手勢(shì)
var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")
//設(shè)置手勢(shì)點(diǎn)擊數(shù),雙擊:點(diǎn)2下
tapGesture.numberOfTapsRequired = 2
self.view.addGestureRecognizer(tapGesture)
2.UIPinchGestureRecognizer 捏 (放大/縮小)手勢(shì)
var pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:")
self.view.addGestureRecognizer(pinchGesture)
3.UIRotationGestureRecognizer 旋轉(zhuǎn)手勢(shì)
var rotateGesture = UIRotationGestureRecognizer(target: self, action: "handleRotateGesture:")
self.view.addGestureRecognizer(rotateGesture)
4. UIPanGestureRecognizer 拖動(dòng)手勢(shì)
var panGesture = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")
self.view.addGestureRecognizer(panGesture)
5. UISwipeGestureRecognizer 劃動(dòng)手勢(shì)
var swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:")
swipeGesture.direction = UISwipeGestureRecognizerDirection.Left //不設(shè)置是右
self.view.addGestureRecognizer(swipeGesture)
6. UILongPressGestureRecognizer 長(zhǎng)按手勢(shì)
var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:")
//長(zhǎng)按時(shí)間
// longpressGesutre.minimumPressDuration
//所需觸摸次數(shù)
/// longpressGesutre.numberOfTouchesRequired
self.view.addGestureRecognizer(longpressGesutre)
UIGestureRecognizerState 枚舉定義如下
enum UIGestureRecognizerState : Int {
case Possible // the recognizer has not yet recognized its gesture, but may be evaluating touch events. this is the default state
case Began // the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop
case Changed // the recognizer has received touches recognized as a change to the gesture. the action method will be called at the next turn of the run loop
case Ended // the recognizer has received touches recognized as the end of the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible
case Cancelled // the recognizer has received touches resulting in the cancellation of the gesture. the action method will be called at the next turn of the run loop. the recognizer will be reset to UIGestureRecognizerStatePossible
case Failed // the recognizer has received a touch sequence that can not be recognized as the gesture. the action method will not be called and the recognizer will be reset to UIGestureRecognizerStatePossible
}
相關(guān)文章
swift3.0鍵盤(pán)彈起遮擋輸入框問(wèn)題的解決方案
這篇文章主要介紹了swift3.0鍵盤(pán)彈起遮擋輸入框問(wèn)題的解決方案,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11
RxSwift學(xué)習(xí)之Observable的新建、訂閱及取消訂閱
這篇文章主要給大家介紹了關(guān)于RxSwift學(xué)習(xí)教程之Observable的相關(guān)資料,文中詳細(xì)的給大家介紹了關(guān)于新建Observable、訂閱Observable和取消訂閱并消除內(nèi)存泄漏等相關(guān)的內(nèi)容,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-09-09
SwiftUI開(kāi)發(fā)總結(jié)combine原理簡(jiǎn)單示例詳解
這篇文章主要為大家介紹了SwiftUI開(kāi)發(fā)總結(jié)combine原理簡(jiǎn)單示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
swift在IOS應(yīng)用圖標(biāo)上添加提醒個(gè)數(shù)的方法
本文是通過(guò)swift語(yǔ)言實(shí)現(xiàn)在應(yīng)用圖標(biāo)右上角添加消息個(gè)數(shù)提醒的功能,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-08-08
詳解Swift編程中的for循環(huán)的編寫(xiě)方法
這篇文章主要介紹了Swift編程中的for循環(huán)的編寫(xiě)方法,包括相關(guān)的for...in循環(huán),需要的朋友可以參考下2015-11-11
Swift 字符串類(lèi)型及常用方法詳解總結(jié)
Swift 字符串是一系列字符的集合。例如 "Hello, World!" 這樣的有序的字符類(lèi)型的值的集合,它的數(shù)據(jù)類(lèi)型為 String,接下來(lái)文章將詳細(xì)探討2021-11-11
Swift使用enum抹平數(shù)組元素差異實(shí)例詳解
這篇文章主要為大家介紹了Swift使用enum抹平數(shù)組元素差異實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Swift中Optional值的鏈?zhǔn)秸{(diào)用學(xué)習(xí)筆記
這篇文章主要介紹了Swift中Optional值的鏈?zhǔn)秸{(diào)用學(xué)習(xí)筆記,Optional鏈?zhǔn)荢wift入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2016-07-07

