- UITapGestureRecognizer – “轻击”手势。可以配置为“单击”和“连击”的识别。
- UIPinchGestureRecognizer –“捏合”手势。该手势通常用于缩放视图或改变可视组件的大小。
- UIPanGestureRecognizer – “平移”手势。识别拖拽或移动动作。
- UISwipeGestureRecognizer – “轻扫”手势。当用户从屏幕上划过时识别为该手势。可以指定该动作的方向(上、下、左、右)。
- UIRotationGestureRecognizer – “转动”手势。用户两指在屏幕上做相对环形运动。
- UILongPressGestureRecognizer – “长按”手势。使用一指或多指触摸屏幕并保持一定时间。
- 这里以单击为例
- 一、首先在一个视图中添加一个imageview控件,用以添加一个图像。
-
- self.productImageView.image = [UIImage imageNamed:@"iPhone.jpg"];
//轻点 添加手势 - // 单击
- UITapGestureRecognizer *SingleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetImage:)];
- SingleTapGesture.numberOfTapsRequired = 1;//tap次数 (手指数量)
- [self.view addGestureRecognizer:SingleTapGesture];
- //单击恢复视图
- - (void)resetImage:(UITapGestureRecognizer *)recognizer
- { // 方法里面做你单击要实现的动作
- [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:0.3];
- self.productImageView.transform = CGAffineTransformIdentity;
- [self.productImageView setCenter:CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2)];
- [UIView commitAnimations];
- }
捏合手势
- // 处理捏合缩放手势
- - (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
- {
- UIView *view = self.productImageView;
- if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
- view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
- pinchGestureRecognizer.scale = 1;
- }
- }
- 其他的以此类推 注意手指数量 手指滑动方向等
- self.productImageView.image = [UIImage imageNamed:@"iPhone.jpg"];
时间: 2024-10-08 02:06:56