iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
其余的请见:http://blog.csdn.net/totogo2010/article/details/8615940
1、UIGestureRecognizer介绍
- UITapGestureRecognizer
- UIPinchGestureRecognizer
- UIRotationGestureRecognizer
- UISwipeGestureRecognizer
- UIPanGestureRecognizer
- UILongPressGestureRecognizer
- Tap(点一下)
- Pinch(二指往內或往外拨动,平时经常用到的缩放)
- Rotation(旋转)
- Swipe(滑动,快速移动)
- Pan (拖移,慢速移动)
- LongPress(长按)
2、使用手势的步骤
- 创建手势实例。当创建手势时,指定一个回调方法,当手势开始,改变、或结束时,回调方法被调用。
- 添加到需要识别的View中。每个手势只对应一个View,当屏幕触摸在View的边界内时,如果手势和预定的一样,那就会回调方法。
3、Pan 拖动手势:
- UIImageView *snakeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"snake.png"]];
- snakeImageView.frame = CGRectMake(50, 50, 100, 160);
- UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]
- initWithTarget:self
- action:@selector(handlePan:)];
- [snakeImageView addGestureRecognizer:panGestureRecognizer];
- [self.view setBackgroundColor:[UIColor whiteColor]];
- [self.view addSubview:snakeImageView];
- - (void) handlePan:(UIPanGestureRecognizer*) recognizer
- {
- CGPoint translation = [recognizer translationInView:self.view];
- recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
- recognizer.view.center.y + translation.y);
- [recognizer setTranslation:CGPointZero inView:self.view];
- }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。