双击
var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")
//设置手势点击数,双击:点2下
tapGesture.numberOfTapsRequired = 2
self.view.addGestureRecognizer(tapGesture)
func handleTapGesture(sender: UITapGestureRecognizer){
}
捏
//手势为捏的姿势:按住option按钮配合鼠标来做这个动作在虚拟器上
var pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:")
self.view.addGestureRecognizer(pinchGesture)
//捏手势做缩放比例
func handlePinchGesture(sender: UIPinchGestureRecognizer){
if sender.scale > 1{
//图片放大
}else{
//缩小
}
}
旋转
//旋转手势:按住option按钮配合鼠标来做这个动作在虚拟器上
var rotateGesture = UIRotationGestureRecognizer(target: self, action: "handleRotateGesture:")
self.view.addGestureRecognizer(rotateGesture)
func handleRotateGesture(sender: UIRotationGestureRecognizer){
//浮点类型,得到sender的旋转度数
var rotation : CGFloat = sender.rotation
}
拖
var panGesture = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")
self.view.addGestureRecognizer(panGesture)
func handlePanGesture(sender: UIPanGestureRecognizer){
//得到拖的过程中的xy坐标
var translation : CGPoint = sender.translationInView(imgView)
}
划动
//右划
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)
func handleSwipeGesture(sender: UISwipeGestureRecognizer){
//划动的方向
var direction = sender.direction
//判断是上下左右
switch (direction){
case UISwipeGestureRecognizerDirection.Left:
break
case UISwipeGestureRecognizerDirection.Right:
break
default:
break;
}
}
长按
//长按手势
var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:")
//最小长按时间为1秒
longpressGesutre.minimumPressDuration = 1
//允许像素的最大移动
longpressGesutre.allowableMovement = 15
//要识别的手势必须保持的手指数
longpressGesutre.numberOfTouchesRequired = 1
self.view.addGestureRecognizer(longpressGesutre)
func handleLongpressGesture(sender : UILongPressGestureRecognizer){
//手势状态,开始、结束、失败、取消...
if sender.state == UIGestureRecognizerState.Began{
} else if sender.state == UIGestureRecognizerState.Ended {
}
}
网友评论