各種觸摸手勢(shì)介紹

1.輕拍手勢(shì)

let tap = UITapGestureRecognizer()
        self.view.addGestureRecognizer(tap)
        tap.addTarget(self, action: #selector(topAction))
        //拍幾下
        tap.numberOfTapsRequired=2
        //幾個(gè)手指拍
        tap.numberOfTouchesRequired = 2
 func tapAction(){
        print("輕拍")
    }

2.長(zhǎng)按手勢(shì)

let long = UILongPressGestureRecognizer()
        self.view.addGestureRecognizer(long)
        long.addTarget(self, action: #selector(longAction))
        //長(zhǎng)按事件 默認(rèn)是0.5
        long.minimumPressDuration = 1
        //長(zhǎng)按時(shí)可以挪動(dòng)的最小距離,默認(rèn)是10
        long.allowableMovement = 15
        //長(zhǎng)按手指數(shù)量,次數(shù)同輕拍
  func longAction(){
         print("長(zhǎng)按")
    }

3.輕掃

let swip = UISwipeGestureRecognizer()
        swip.direction = .left
        swip.addTarget(self, action: #selector(swipAction(swip:)))
        self.view.addGestureRecognizer(swip)
        let swip1 = UISwipeGestureRecognizer()
        swip.direction = .right
        swip.addTarget(self, action: #selector(swipAction(swip:)))
        self.view.addGestureRecognizer(swip1)
 func swipAction(swip:UISwipeGestureRecognizer){
        // 獲取輕掃的方向
        let dir=swip.direction
        //print(dir)
        if dir == .left{
           
        }else if dir == .right {
            
        }
       // print("輕掃的方向\(dir)")
    }

4.旋轉(zhuǎn)手勢(shì)

let rota = UIRotationGestureRecognizer()
        ()
        self.view.addGestureRecognizer(rota)
        rota.addTarget(self,action:#selector(rotaAction))
        //旋轉(zhuǎn)角度
        // rota.rotation
func rotaAction(){
        
    }

5.捏合手勢(shì)

 let pin = UIPinchGestureRecognizer()
        pin.addTarget(self, action: #selector(pinAction))
        self.view.addGestureRecognizer(pin)
        //縮放比
        //pin.scale
  func pinAction(){
        print("捏合")
    }

6.拖動(dòng)手勢(shì)

 let pan = UIPanGestureRecognizer()
        pan.addTarget(self, action: #selector(panAction(pan:)))
        //pan.translation(in: <#T##UIView?#>)
        self.view.addGestureRecognizer(pan)
  func panAction(pan:UIPanGestureRecognizer){
        print(pan.translation(in: self.view))
    }
       

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容