//UIGestureRecognizer ?手勢識(shí)別器
? ?//七中手勢:輕拍(tap) 長按(longPress) 旋轉(zhuǎn)(rotation) 捏合(pinch) 拖拽(pan)
? ? ? ? ? ? // 輕掃(swipe) 屏幕邊緣拖拽(screEdgePan)
? ?//圖片
? ?UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
? ?imgView.center = self.view.center;
? ?imgView.image = [UIImage imageNamed:@""];
? ?[self.view addSubview:imgView];
? ?[imgView release];
? ?//打開用戶交互
? ?imgView.userInteractionEnabled = YES;
//一 輕拍(tap)
? ?//獲取到輕拍手勢時(shí),讓self調(diào)用tapAction:方法
? ?UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
? ?//添加手勢
? ?[imgView addGestureRecognizer:tap];
? ?//內(nèi)存管理
? ?[tap release];
? ?//點(diǎn)擊次數(shù)
? ?tap.numberOfTapsRequired = 2;
? ?//手指個(gè)數(shù)
? ?tap.numberOfTouchesRequired = 1;
//二 長按(longPress)
? ?UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction::)];
? ?[imgView addGestureRecognizer:longPress];
? ?[longPress release];
? ?//長按時(shí)間
? ?longPress.minimumPressDuration = 0.2;
//三 旋轉(zhuǎn)(rotation)
? ?UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
? ?[imgView addGestureRecognizer:rotation];
? ?[rotation release];
//四 捏合(pinch)
? ?UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAciton:)];
? ?[imgView addGestureRecognizer:pinch];
? ?[pinch release];
//五 輕掃(swipe)
? ?UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
? ?//默認(rèn)只識(shí)別向右
? ?//設(shè)置方向時(shí) 最多只能設(shè)置 水平(左/右)或者垂直(上/下)
? ?swipe.direction = UISwipeGestureRecognizerDirectionLeft |UISwipeGestureRecognizerDirectionRight |UISwipeGestureRecognizerDirectionDown |UISwipeGestureRecognizerDirectionUp;
? ?[imgView addGestureRecognizer:swipe];
? ?[swipe release];
//六 pan(拖拽)
? ?UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
? ?[imgView addGestureRecognizer:pan];
? ?[pan release];
//七 屏幕邊緣拖拽(sreenEdgePan)
? ?UIScreenEdgePanGestureRecognizer *sep = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(sepAction:)];
? ?//需要設(shè)置拖拽的邊緣
? ?sep.edges = UIRectEdgeLeft;
? ?//一般這個(gè)手勢添加在VC的view上
? ?[self.view addGestureRecognizer:sep];
? ?[sep release];