self.view.backgroundColor = [UIColor whiteColor];
//UIGestureRecognizer 手势识别器
//手势: 有规律的触摸
// UIGestureRecognizer 抽象类
//七种手势: 轻拍(tap) 长按(longPress) 旋转(rotation) 捏合(pinch) 拖拽(pan) 清扫(swipe) 屏幕边缘拖拽(screenEdgepan)
//图片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
imageView.center = self.view.center;
//imageView.image = [UIImage imageNamed:@"1.jpg"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpg"];
imageView.image = [UIImage imageWithContentsOfFile:path];
[self.view addSubview:imageView];
[imageView release];
//打开用户交互
imageView.userInteractionEnabled = YES;
#if 0
/*轻拍*/
// 创建对象
//获取到轻拍手势 让self调用tapAction:方法
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//添加手势
[imageView addGestureRecognizer:tap];
//内存管理
[tap release];
//点击次数(默认为1)
tap.numberOfTapsRequired = 2;
//手指个数
tap.numberOfTouchesRequired = 2;
#endif
#if 0
/*长按*/
UILongPressGestureRecognizer *lp = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
[imageView addGestureRecognizer:lp];
[lp release];
//长按时间
lp.minimumPressDuration = 1;
#endif
#if 0
/*旋转 rotation*/
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];
[imageView addGestureRecognizer:rotation];
[rotation release];
#endif
#if 0
/*捏合pinch*/
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
[imageView addGestureRecognizer:pinch];
[pinch release];
#endif
#if 0
/*清扫*/
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
//设置方向(只支持一个方向)
swipe.direction = UISwipeGestureRecognizerDirectionRight;//向右清扫
[imageView addGestureRecognizer:swipe];
[swipe release];
#endif
#if 0
/*拖拽*/
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
[imageView addGestureRecognizer:pan];
[pan release];
#endif
#if 1
/*边缘拖拽*/
UIScreenEdgePanGestureRecognizer *edgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(edgePanAction:)];
//边缘平移只支持一个方向
edgePan.edges = UIRectEdgeLeft;
[imageView addGestureRecognizer:edgePan];
[edgePan release];
#endif
网友评论