触摸,手势
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 275, 500)] autorelease];
imageView.image = [UIImage imageNamed:@"love.jpg"];
imageView.userInteractionEnabled = YES;
//1、创建满足需求的手势,在创建时关联手势触发时的方法
//2、配置手势的相关属性
//3、将手势添加w 到需要执行操作的视图上面
//4、实现手势方法,当触摸发生,手势识别器识别到想对应的触摸时,就会执行关联的方法
//轻拍手势 UITapGestureRecognizer
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)] autorelease];
//设置属性
//1、出发手势的手指个数
tap.numberOfTouchesRequired = 1;
//2、触发手势的轻拍次数
tap.numberOfTapsRequired = 1;
//3、让imageView添加手势
[imageView addGestureRecognizer:tap];
/*
//轻扫手势
UISwipeGestureRecognizer *swipe = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)] autorelease];
//指定轻扫的方向
// swipe.direction = UISwipeGestureRecognizerDirectionDown;
[imageView addGestureRecognizer:swipe];
*/
/*
//长按手势
UILongPressGestureRecognizer *longpress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpressAction:)] autorelease];
//长按手势触发的最短时间,默认是0.5
longpress.minimumPressDuration = 1.0;
[imageView addGestureRecognizer:longpress];
*/
/*
//缩放
UIPinchGestureRecognizer *pinch = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)] autorelease];
[imageView addGestureRecognizer:pinch];
*/
/*
//旋转
UIRotationGestureRecognizer *rotate = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateAction:)] autorelease];
[imageView addGestureRecognizer:rotate];
*/
/*
//平移
UIPanGestureRecognizer *pan = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)] autorelease];
[imageView addGestureRecognizer:pan];
*/