手勢(shì):有規(guī)律的觸摸
UIGestureRecognizer抽象類
七種手勢(shì):輕拍(tap)長(zhǎng)按(longPress)旋轉(zhuǎn)(rotation)捏合(pinch)拖拽(pan)清掃(swipe)屏幕邊緣拖拽(screenEdgePan)
//添加手勢(shì)
[imgView addGestureRecongnizer:tap];
//內(nèi)存管理
[top release];
//長(zhǎng)按(longPress)
UILongPressGestureRecongnizer *longPress = [UILongPressGestureRecognizer alloc]initwithTarget:Self action:@selector(longPressAction:)]; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [ longPress release];
//長(zhǎng)按時(shí)間
longPress.minimumPressDuration = 1;
//旋轉(zhuǎn)(rotation)
UIRotationGestureRecognizer *rotation = [UIRotationGestureRecongnizer alloc]initWithTarget:selfaction:@selector(pinchAction:)]; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[imgView addGestureRecognizer:pinch]; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[pinch release];
?// UIView transform屬性 專門用來進(jìn)行形變(位置position/旋轉(zhuǎn)rotation/縮放scale)設(shè)置
? ?// 獲取當(dāng)前手勢(shì)觸發(fā)的視圖
? ?UIImageView *imgView = (UIImageView *)rotation.view;
? ?// 設(shè)置transfrom實(shí)現(xiàn)旋轉(zhuǎn)
? ?imgView.transform = CGAffineTransformMakeRotation(rotation.rotation);
//拖拽(pan)同上
?// 拖拽視圖
? ?UIImageView *imgView = (UIImageView *)pan.view;
? ?// 獲取拖拽時(shí) 經(jīng)過的點(diǎn)
? ?CGPoint p = [pan translationInView:imgView];
? ?// 設(shè)置transform
? ?imgView.transform = CGAffineTransformMakeTranslation(p.x, p.y);
//捏合(pinch)同上
// 獲取view
? ?UIImageView *imgView = (UIImageView *)pinch.view;
? ?// 如果使用makeScale函數(shù) 不需要設(shè)置比例系數(shù)
? ?imgView.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
//輕掃(swipe)
UISwipeGestureRecognizer *swipe = [UISwipeGestureRecongnizer alloc]initWithTarget:selfaction:@selector(pinchAction:)];
//默認(rèn)只識(shí)別向右 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
//設(shè)置方向時(shí) 最多只能設(shè)置水平(左/右)或者垂直(上/下)
swipe.direction = UISwipeGestureRecognizerDirectionRight
UISwipeGstureRecognizerDirectionLefet;
[imgView addGestureRecognizer:swipe]; ?
//屏幕邊緣拖拽(screenEdgePan)
UIScreenEdgePanGestureRecognizer *sep = [UIScreenEdgePanGestureRecongnizer alloc]initWithTarget:selfaction:@selector(pinchAction:)];
//需要設(shè)置拖拽的邊緣
sep.edges = UIRectEdgeLeft;
//一般這個(gè)手勢(shì)添加在VC的view上
[self.view addGestureRecognizer:sep];
[sep release];