UIImageView *imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height)];
imageView.backgroundColor = [UIColorgreenColor];
imageView.image = [UIImageimageNamed:@"/Users/dllo/Desktop/G[E@OFJNXNW(Y$_OIVOLH9L.jpg"];
imageView.contentMode =UIViewContentModeScaleAspectFill;
imageView.userInteractionEnabled =YES;
[self.viewaddSubview:imageView];
[imageViewrelease];
// 1.点击手势(tap)
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(tapClick:)];
// 执行方法需要点击的次数
tap.numberOfTapsRequired =2;
// 需要几个手指点击
tap.numberOfTouchesRequired =1;
[imageViewaddGestureRecognizer:tap];
[taprelease];
- (void)tapClick:(UITapGestureRecognizer *)tap {
NSLog(@"点击手势");
}
// 2.长按手势 (longpress)
UILongPressGestureRecognizer *lon = [[UILongPressGestureRecognizeralloc] initWithTarget:selfaction:@selector(longPress:)];
// 默认0.5 -- 长按需要的时间
lon.minimumPressDuration =3;
// 长按判定中允许用户手指移动的距离
lon.allowableMovement =100;
lon.numberOfTouchesRequired =1;
[imageViewaddGestureRecognizer:lon];
[lonrelease];
- (void)longPress:(UILongPressGestureRecognizer *)lon {
NSLog(@"长按手势");
}
// 3.旋转手势(rotation)
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizeralloc] initWithTarget:selfaction:@selector(rotationPress:)];
[imageViewaddGestureRecognizer:rotation];
[rotationrelease];
- (void)rotationPress:(UIRotationGestureRecognizer *)rontation {
NSLog(@"旋转手势");
UIView *imageV = rontation.view;
imageV.transform = CGAffineTransformRotate(imageV.transform, rontation.rotation);
rontation.rotation = 0;
}
// 4.捏合
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc] initWithTarget:selfaction:@selector(pinchPress:)];
[imageViewaddGestureRecognizer: pinch];
[pinchrelease];
- (void)pinchPress:(UIPinchGestureRecognizer *)pinch {
NSLog(@"捏合手势");
// 获得手势所在的view
UIView *imageV = pinch.view;
imageV.transform = CGAffineTransformScale(imageV.transform, pinch.scale, pinch.scale);
pinch.scale = 1;
}
// 5.平移
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc] initWithTarget:selfaction:@selector(panPress:)];
[imageViewaddGestureRecognizer:pan];
[panrelease];
- (void)panPress:(UIPanGestureRecognizer*)pan {
NSLog(@"平移手势");
UIView *imageV = pan.view;
CGPoint point = [pan translationInView:imageV];
imageV.transform= CGAffineTransformTranslate(imageV.transform, point.x,point.y);
[pan setTranslation:CGPointZeroinView:imageV];
}
// 6.轻扫
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizeralloc] initWithTarget:selfaction:@selector(swipePress:)];
[imageViewaddGestureRecognizer:swipe];
[swiperelease];
- (void)swipePress:(UISwipeGestureRecognizer *)swipe {
NSLog(@"轻扫手势");
}
// 7.屏幕边缘轻扫识别器
UIScreenEdgePanGestureRecognizer *screen = [[UIScreenEdgePanGestureRecognizeralloc] initWithTarget:selfaction:@selector(screenPress:)];
- (void)screenPress:(UIScreenEdgePanGestureRecognizer *)screen {
NSLog(@"屏幕边缘");
}