Swift中實現(xiàn)點擊、雙擊、捏、旋轉、拖動、劃動、長按手勢的類和方法介紹
1.UITapGestureRecognizer 點擊/雙擊手勢
var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")
//設置手勢點擊數(shù),雙擊:點2下
tapGesture.numberOfTapsRequired = 2
self.view.addGestureRecognizer(tapGesture)
2.UIPinchGestureRecognizer 捏 (放大/縮小)手勢
var pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:")
self.view.addGestureRecognizer(pinchGesture)
3.UIRotationGestureRecognizer 旋轉手勢
var rotateGesture = UIRotationGestureRecognizer(target: self, action: "handleRotateGesture:")
self.view.addGestureRecognizer(rotateGesture)
4. UIPanGestureRecognizer 拖動手勢
var panGesture = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")
self.view.addGestureRecognizer(panGesture)
5. UISwipeGestureRecognizer 劃動手勢
var swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:")
swipeGesture.direction = UISwipeGestureRecognizerDirection.Left //不設置是右
self.view.addGestureRecognizer(swipeGesture)
6. UILongPressGestureRecognizer 長按手勢
var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:")
//長按時間
// 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
}
相關文章
SwiftUI 中創(chuàng)建反彈動畫的實現(xiàn)
這篇文章主要介紹了SwiftUI 中創(chuàng)建反彈動畫的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-10-10switch實現(xiàn)一個兩數(shù)的運算代碼示例
這篇文章主要介紹了switch實現(xiàn)一個兩數(shù)的運算代碼示例,需要的朋友可以參考下2017-06-06mac git xcrun error active developer path 錯誤
本文主要是講訴了如何解決在mac下使用git;xcode4.6的環(huán)境時,出現(xiàn)了錯誤(mac git xcrun error active developer path)的解決辦法,希望對大家有所幫助2014-09-09iOS Swift UICollectionView橫向分頁滾動,cell左右排版問題詳解
UICollectionView是iOS中比較常見的一個控件,這篇文章主要給大家介紹了關于iOS Swift UICollectionView橫向分頁滾動,cell左右排版問題的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨小編來一起學習學習吧。2017-12-12