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

各种触摸手势介绍

作者: 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))
    }
       

相关文章

  • 各种触摸手势介绍

    1.轻拍手势 2.长按手势 3.轻扫 4.旋转手势 5.捏合手势 6.拖动手势

  • iOS 手势操作 geekband

    什么是触摸手势 触摸手势的原理 UIControl 离散与断续 手势识别状态 小案例 新建文件在storyboar...

  • Android手势---GestureDetector

    GestureDetector 可以使用 MotionEvents 检测各种手势和事件。 这个类只能用于检测触摸事...

  • iOS开发经验(16)-响应机制、触摸事件、手势识别器

    目录 响应机制、触摸事件 手势识别器 手势识别与事件响应混用 1. 响应机制 在用户使用app的过程中,会产生各种...

  • UI手势回顾

    UIGestureRecongnizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象...

  • UI4_手势识别器

    //UIGestureRecognizer 手势识别器 //手势:有规律的触摸 // UIGestureReco...

  • 如何精确响应手势识别位置

    子视图并不响应 tap 点击触摸手势 , 而是至于父视图响应 tap 触摸手势的效果 , 精确定位触摸的位置: 1...

  • iOS手势识别器

    1.手势识别器 1.手势识别器是iOS中比较抽象的一个类,用于识别一个手势,所谓手势:有规律的触摸。是对触摸事件做...

  • UI - 手势

    UIGestureRecognizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象类...

  • UI手势

    UIGestureRecognizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象类...

网友评论

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

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