iOS开发之手势识别
|
1 //常摁手势触发方法
2 -(void)longPressGesture:(id)sender
3 {
4 UILongPressGestureRecognizer *longPress = sender;
5 if (longPress.state == UIGestureRecognizerStateBegan)
6 {
7 UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"长按触发" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil];
8 [alter show];
9 }
10 }
|
|
1 //轻扫手势触发方法
2 -(void)swipeGesture:(id)sender
3 {
4 UISwipeGestureRecognizer *swipe = sender;
5 if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
6 {
7 //向左轻扫做的事情
8 }
9 if (swipe.direction == UISwipeGestureRecognizerDirectionRight)
10 {
11 //向右轻扫做的事情
12 }
13 }
14
|
|
1 ////捏合手势触发方法
2 -(void) pinchGesture:(id)sender
3 {
4 UIPinchGestureRecognizer *gesture = sender;
5
6 //手势改变时
7 if (gesture.state == UIGestureRecognizerStateChanged)
8 {
9 //捏合手势中scale属性记录的缩放比例
10 _imageView.transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale);
11 }
12
13 //结束后恢复
14 if(gesture.state==UIGestureRecognizerStateEnded)
15 {
16 [UIView animateWithDuration:0.5 animations:^{
17 _imageView.transform = CGAffineTransformIdentity;//取消一切形变
18 }];
19 }
20 }
|
|
1 //旋转手势
2 -(void)rotationGesture:(id)sender
3 {
4
5 UIRotationGestureRecognizer *gesture = sender;
6
7 if (gesture.state==UIGestureRecognizerStateChanged)
8 {
9 _imageView.transform=CGAffineTransformMakeRotation(gesture.rotation);
10 }
11
12 if(gesture.state==UIGestureRecognizerStateEnded)
13 {
14
15 [UIView animateWithDuration:1 animations:^{
16 _imageView.transform=CGAffineTransformIdentity;//取消形变
17 }];
18 }
19
20 }
|

