第二周第二天手势

手势

  • 轻拍
  • 长按
  • 几个手指轻拍
  • 长按时可以挪动的最小距离(默认10)
  • 长按的手指数数量和次数同轻拍
  • 清扫
  • 旋转
  • 捏合
  • 拖动
  • 缩放
 //手势
        
        /*
        //轻拍
        let tap = UITapGestureRecognizer()
        //添加到view上
        self.view.addGestureRecognizer(tap)
        tap.addTarget(self, action: #selector(tapAction))
        //几个手指轻拍
        tap.numberOfTouchesRequired = 2
        //拍几下
        tap.numberOfTapsRequired = 2
        */
        
        
        /*
        //长按
        let long = UILongPressGestureRecognizer()
        //添加到view上
        self.view.addGestureRecognizer(long)
        long.addTarget(self, action: #selector(longAction))
        //最小长按时间(默认0.5)
        long.minimumPressDuration = 1
        //长按时可以挪动的最小距离(默认10)
        long.allowableMovement = 15
        //长按的手指数数量和次数同轻拍
        */
        
        
        /*
        //清扫
        let swipe = UISwipeGestureRecognizer()
        swipe.direction = .left
        self.view.addGestureRecognizer(swipe)
        swipe.addTarget(self, action: #selector(swipeAction(swipe:)))
        
        let swipe1 = UISwipeGestureRecognizer()
        swipe.direction = .right
        self.view.addGestureRecognizer(swipe1)
        swipe1.addTarget(self, action: #selector(swipeAction(swipe:)))
        */
        
        
        /*
        //旋转
        let rotation = UIRotationGestureRecognizer()
        self.view.addGestureRecognizer(rotation)
        rotation.addTarget(self, action: #selector(rotationAction))
        //旋转角度
        //rotation.rotation
        */
        
        /*
        //捏合
        let pinch = UIPinchGestureRecognizer()
        self.view.addGestureRecognizer(pinch)
        pinch.addTarget(self, action: #selector(pinchAction))
        //缩放
        //pinch.scale
        */
        
        
        //拖动
        let pan = UIPanGestureRecognizer()
        pan.addTarget(self, action: #selector(panAction(pan:)))
        self.view.addGestureRecognizer(pan)
        //缩放
        //pan.scale
        //拖动坐标 pan.translation
        
    }
    
    //UIPinchGestureRecognizer拖动方法
    func panAction(pan:UIPanGestureRecognizer) {
        //返回当前拖动的位置在self.view上的位置
         print(pan.translation(in: self.view))
    }
    
    //UIPinchGestureRecognizer捏合方法
    func pinchAction() {
        print("捏合")
    }
    
    //UIRotationGestureRecognizer旋转方法
    func rotationAction() {
        print("旋转")
    }
    
    //UISwipeGestureRecognizer清扫方法
    //传参:往哪个方向扫
    func swipeAction(swipe: UISwipeGestureRecognizer) {
        //获取清扫方向
        let dir = swipe.direction
        //print("向左清扫")
        //print("清扫的方向:\(dir)")
        if dir == .left {
            
        } else if dir == .right {
            
        }
    }
    
    //UILongPressGestureRecognizer长按方法
    func longAction() {
        print("长按")
    }
    
    //UITapGestureRecognizer轻拍方法
    func tapAction() {
        print("轻拍")
    }
    
   }

你可能感兴趣的:(第二周第二天手势)