美文网首页
各种触摸手势介绍

各种触摸手势介绍

作者: Grt婷 | 来源:发表于2016-11-23 09:27 被阅读0次

    1.轻拍手势

    let tap = UITapGestureRecognizer()
            self.view.addGestureRecognizer(tap)
            tap.addTarget(self, action: #selector(topAction))
            //拍几下
            tap.numberOfTapsRequired=2
            //几个手指拍
            tap.numberOfTouchesRequired = 2
     func tapAction(){
            print("轻拍")
        }
    
    

    2.长按手势

    let long = UILongPressGestureRecognizer()
            self.view.addGestureRecognizer(long)
            long.addTarget(self, action: #selector(longAction))
            //长按事件 默认是0.5
            long.minimumPressDuration = 1
            //长按时可以挪动的最小距离,默认是10
            long.allowableMovement = 15
            //长按手指数量,次数同轻拍
      func longAction(){
             print("长按")
        }
    
    

    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.旋转手势

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

    5.捏合手势

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

    6.拖动手势

     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))
        }
           
    
    

    相关文章

      网友评论

          本文标题:各种触摸手势介绍

          本文链接:https://www.haomeiwen.com/subject/senmpttx.html