手势

作者: 也许________ | 来源:发表于2017-06-29 14:29 被阅读12次

    <li>轻触</li><li>轻扫</li><li>长按</li><li>旋转</li><li>捏合</li><li>平移</li><li>边缘</li>
    <h5>轻触</h5>
    <pre>
    func tapGes() {

        let tapGes = UITapGestureRecognizer(target: self, action: #selector(self.tapAction))
        // 轻触几次
        tapGes.numberOfTapsRequired = 2
        // 几根手指
        tapGes.numberOfTouchesRequired = 2
        testImageView.addGestureRecognizer(tapGes)
        
    }
    
    func tapAction() {
        print("轻触")
    }
    

    </pre>

    <h5>轻扫(多个轻扫方向,需要写不同的手势)</h5>
    <pre>

    func swipeGes() {
        
        let downSwipeGes = UISwipeGestureRecognizer(target: self, action: #selector(self.swipeAction(ges:)))
        downSwipeGes.direction = .down
        testImageView.addGestureRecognizer(downSwipeGes)
        
        let leftSwipeGes = UISwipeGestureRecognizer(target: self, action: #selector(self.swipeAction(ges:)))
        leftSwipeGes.direction = .left
        testImageView.addGestureRecognizer(leftSwipeGes)
        
    }
    
    func swipeAction(ges:UISwipeGestureRecognizer) {
    
        switch ges.direction {
        case UISwipeGestureRecognizerDirection.up:
            print("向上轻扫")
        case UISwipeGestureRecognizerDirection.down:
            print("向下轻扫")
        case UISwipeGestureRecognizerDirection.left:
            print("向左轻扫")
        case UISwipeGestureRecognizerDirection.right:
            print("向右轻扫")
        default:
            print("其他")
        }
        
    }
    

    </pre>

    <h5>长按</h5>
    <pre>
    func longGes() {

        let longPressGes = UILongPressGestureRecognizer(target: self, action: #selector(self.longPressAction))
        testImageView.addGestureRecognizer(longPressGes)
    }
    
    func longPressAction() {
        print("长按手势")
    }
    

    </pre>

    <h5>旋转</h5>
    <pre>
    func rotationGes() {
    let rotationGes = UIRotationGestureRecognizer(target: self, action: #selector(self.rotationGesAction))
    testImageView.addGestureRecognizer(rotationGes)
    }

    func rotationGesAction() {
        print("旋转手势")
    }
    

    </pre>

    <h5>捏合</h5>
    <pre>
    func pinchGes() {

        let pinchGes = UIPinchGestureRecognizer(target: self, action: #selector(self.pinchGesAction))
        print("捏合手势----",pinchGes.numberOfTouches)
        testImageView.addGestureRecognizer(pinchGes)
        
    }
    
    func pinchGesAction() {
        print("捏合手势")
    }
    

    </pre>

    <h5>平移</h5>
    <pre>
    func panGes() {

        let panGes = UIPanGestureRecognizer(target: self, action: #selector(self.panGesAction))
        testImageView.addGestureRecognizer(panGes)
        
    }
    
    func panGesAction(){
        print("平移手势")
        print("-------")
    }
    

    </pre>

    <h5>边缘(需要指定边缘方向,手势才会生效)</h5>
    <pre>
    func screenGes() {

       let screenGes = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(self.screenGesAction))
        // 需指定边缘方向,手势才会生效
        screenGes.edges = .left
        testImageView.addGestureRecognizer(screenGes)
    }
    
    func screenGesAction() {
        print("边缘手势")
    }
    

    </pre>

    相关文章

      网友评论

          本文标题:手势

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