swift 添加各种手势

###siwft和OC一样,可以给视图添加各种手势,这里就做一个统一的介绍

  • 点击手势
    var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")  
    //设置手势点击数,双击:点2下  
    // 不设置为单击
    tapGesture.numberOfTapsRequired = 2    
    self.view.addGestureRecognizer(tapGesture) 
  • 捏合手势:按住option按钮配合鼠标来做这个动作在虚拟器上
    var pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:")  
    self.view.addGestureRecognizer(pinchGesture) 
  • 旋转手势:按住option按钮配合鼠标来做这个动作在虚拟器上
    var rotateGesture = UIRotationGestureRecognizer(target: self, action: "handleRotateGesture:")  
    self.view.addGestureRecognizer(rotateGesture)
  • 拖拽手势
    var panGesture = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")  
    self.view.addGestureRecognizer(panGesture)
  • 轻扫手势
    //右划  
    var swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:")  
    self.view.addGestureRecognizer(swipeGesture)  
    //左划  
    var swipeLeftGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:")  
    swipeLeftGesture.direction = UISwipeGestureRecognizerDirection.Left //不设置是右  
    self.view.addGestureRecognizer(swipeLeftGesture)  
  • 长按手势
    var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:")  
    //长按时间为1秒  
    longpressGesutre.minimumPressDuration = 1  
    //允许15秒运动  
    longpressGesutre.allowableMovement = 15  
    //所需触摸1次  
    longpressGesutre.numberOfTouchesRequired = 1  
    self.view.addGestureRecognizer(longpressGesutre) 

转载于:https://my.oschina.net/ozawa4865/blog/703167

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值