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