手势是可以通过代码或者在xib中直接拖进来来生成的
下面介绍动态使用代码来创建手势
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
//点击事件
var atep = UITapGestureRecognizer(target: self, action: "tapDo:")
self.view.addGestureRecognizer(atep)
//单击的次数
atep.numberOfTapsRequired = 1
//拖动的事件
var aPan = UIPanGestureRecognizer(target: self, action: "handlenPan:")
self.view.addGestureRecognizer(aPan)
//最少手指的个数
aPan.minimumNumberOfTouches = 1
//最多的手指的个数
aPan.maximumNumberOfTouches = 3
//长按的事件
var aLongPress = UILongPressGestureRecognizer(target: self, action: "longPress:")
self.view.addGestureRecognizer(aLongPress)
//需要长按的时间 至少 0.5
aLongPress.minimumPressDuration = 0.5
//粘合事件
var aPinch = UIPinchGestureRecognizer(target: self, action: "pinchDo:")
self.view.addGestureRecognizer(aPinch)
//旋转的事件
var aRotation = UIRotationGestureRecognizer(target: self, action: "rotationPiece:")
self.view.addGestureRecognizer(aRotation)
//清扫的事件 左清扫
var leftSwipe = UISwipeGestureRecognizer(target: self, action: "leftSwipe:")
self.view.addGestureRecognizer(leftSwipe)
leftSwipe.direction = UISwipeGestureRecognizerDirection.Left
//左右上下的清扫都一样
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
//实现事件
func tapDo(sender:UITapGestureRecognizer) {
print("点击事件")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
//获取用户默认的函数
}
}
可以用手势来进行模拟
还有很多信息 具体可以看文档