UI手势识别器

七种手势:轻拍(tap)、长按(longPress)、旋转(rotation)、捏合(pinch)、拖拽(pan)、轻扫(swipe)、屏幕边缘拖拽(screenEdgePan)

功能描述:

附加到两个图片视图 UIImageView 的有拖动、捏合、旋转、点按;

而轻扫 附加在根视图 UIView 中。

拖动:进行当前图片视图位置移动

捏合:进行当前图片视图缩放

旋转:进行当前图片视图角度旋转

点按:双击恢复当前图片视图的缩放、角度旋转、不透明度

长按:设置当前图片视图的不透明度为0.7

轻扫:左右轻扫设置两个图片视图为居中,同时以垂直居中的特定偏移量定位

自定义手势:挠痒功能,左右扫动共3次或以上,设置两个图片视图为居中,同时以水平居中的特定偏移量定位

一、轻拍(tap)

 创建对象

获取到轻拍手势时 让self调用tapAction:方法

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

 添加手势

[imgView addGestureRecognizer:tap];

内存管理

[tap release];

点击次数

tap.numberOfTapsRequired = 2;

 手指个数

tap.numberOfTouchesRequired = 2;

二、长按(longPress)

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];

[imgView addGestureRecognizer:longPress];

[longPress release];

设置长按时间

longPress.minimumPressDuration = 1;

三、旋转rotation

UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];

[imgView addGestureRecognizer:rotation];

[rotation release];

四、捏合pinch

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];

[imgView addGestureRecognizer:pinch];

[pinch release];

五、拖拽pan

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];

[imgView addGestureRecognizer:pan];

[pan release];

六、轻扫(swipe)

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];

默认只识别向右

设置方向时 最多只能设置 水平(左/右)或者垂直(上/下)

swipe.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

[imgView addGestureRecognizer:swipe];

[swipe release];

七、屏幕边缘拖拽screenEdgePan

UIScreenEdgePanGestureRecognizer *sep = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(sepAction:)];

需要设置拖拽的边缘

sep.edges = UIRectEdgeLeft;

[self.view addGestureRecognizer:sep];

[sep release];

你可能感兴趣的:(UI手势识别器)