国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Swift > 正文

Swift中實現(xiàn)點擊、雙擊、捏、旋轉、拖動、劃動、長按手勢的類和方法介紹

2020-03-09 17:51:43
字體:
來源:轉載
供稿:網(wǎng)友
這篇文章主要介紹了Swift中實現(xiàn)點擊、雙擊、捏、旋轉、拖動、劃動、長按手勢的類和方法介紹,本文分別給出了各種手勢的實現(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
}



注:相關教程知識閱讀請移步到swift教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 海淀区| 汝州市| 平武县| 锦州市| 佛学| 邯郸市| 吉木乃县| 玛纳斯县| 信丰县| 永登县| 左权县| 长岛县| 灵山县| 三台县| 益阳市| 浪卡子县| 张家港市| 洛川县| 手游| 密山市| 广水市| 沐川县| 阳原县| 壤塘县| 都昌县| 中西区| 双城市| 隆尧县| 泾川县| 资溪县| 南昌县| 蓬溪县| 桑植县| 浦江县| 乐清市| 平利县| 黔西| 化州市| 安泽县| 海伦市| 莱芜市|