手势:有规律的触摸
UIGestureRecognizer抽象类
七种手势:轻拍(tap)长按(longPress)旋转(rotation)捏合(pinch)拖拽(pan)清扫(swipe)屏幕边缘拖拽(screenEdgePan)
//添加手势
[imgView addGestureRecongnizer:tap];
//内存管理
[top release];
//长按(longPress)
UILongPressGestureRecongnizer *longPress = [UILongPressGestureRecognizer alloc]initwithTarget:Self action:@selector(longPressAction:)]; [ longPress release];
//长按时间
longPress.minimumPressDuration = 1;
//旋转(rotation)
UIRotationGestureRecognizer *rotation = [UIRotationGestureRecongnizer alloc]initWithTarget:selfaction:@selector(pinchAction:)]; [imgView addGestureRecognizer:pinch]; [pinch release];
// UIView transform属性 专门用来进行形变(位置position/旋转rotation/缩放scale)设置
// 获取当前手势触发的视图
UIImageView *imgView = (UIImageView *)rotation.view;
// 设置transfrom实现旋转
imgView.transform = CGAffineTransformMakeRotation(rotation.rotation);
//拖拽(pan)同上
// 拖拽视图
UIImageView *imgView = (UIImageView *)pan.view;
// 获取拖拽时 经过的点
CGPoint p = [pan translationInView:imgView];
// 设置transform
imgView.transform = CGAffineTransformMakeTranslation(p.x, p.y);
//捏合(pinch)同上
// 获取view
UIImageView *imgView = (UIImageView *)pinch.view;
// 如果使用makeScale函数 不需要设置比例系数
imgView.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
//轻扫(swipe)
UISwipeGestureRecognizer *swipe = [UISwipeGestureRecongnizer alloc]initWithTarget:selfaction:@selector(pinchAction:)];
//默认只识别向右
//设置方向时 最多只能设置水平(左/右)或者垂直(上/下)
swipe.direction = UISwipeGestureRecognizerDirectionRight
UISwipeGstureRecognizerDirectionLefet;
[imgView addGestureRecognizer:swipe];
//屏幕边缘拖拽(screenEdgePan)
UIScreenEdgePanGestureRecognizer *sep = [UIScreenEdgePanGestureRecongnizer alloc]initWithTarget:selfaction:@selector(pinchAction:)];
//需要设置拖拽的边缘
sep.edges = UIRectEdgeLeft;
//一般这个手势添加在VC的view上
[self.view addGestureRecognizer:sep];
[sep release];