七種手勢(shì):輕拍(tap)悲靴、長(zhǎng)按(longPress)蝎困、旋轉(zhuǎn)(rotation)、捏合(pinch)庄拇、拖拽(pan)注服、輕掃(swipe)韭邓、屏幕邊緣拖拽(screenEdgePan)
功能描述:
附加到兩個(gè)圖片視圖 UIImageView 的有拖動(dòng)、捏合溶弟、旋轉(zhuǎn)女淑、點(diǎn)按;
而輕掃 附加在根視圖 UIView 中辜御。
拖動(dòng):進(jìn)行當(dāng)前圖片視圖位置移動(dòng)
捏合:進(jìn)行當(dāng)前圖片視圖縮放
旋轉(zhuǎn):進(jìn)行當(dāng)前圖片視圖角度旋轉(zhuǎn)
點(diǎn)按:雙擊恢復(fù)當(dāng)前圖片視圖的縮放鸭你、角度旋轉(zhuǎn)、不透明度
長(zhǎng)按:設(shè)置當(dāng)前圖片視圖的不透明度為0.7
輕掃:左右輕掃設(shè)置兩個(gè)圖片視圖為居中擒权,同時(shí)以垂直居中的特定偏移量定位
袱巨?自定義手勢(shì):撓癢功能,左右掃動(dòng)共3次或以上菜拓,設(shè)置兩個(gè)圖片視圖為居中瓣窄,同時(shí)以水平居中的特定偏移量定位
一笛厦、輕拍(tap)
?創(chuàng)建對(duì)象
獲取到輕拍手勢(shì)時(shí) 讓self調(diào)用tapAction:方法
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
?添加手勢(shì)
[imgView addGestureRecognizer:tap];
內(nèi)存管理
[tap release];
點(diǎn)擊次數(shù)
tap.numberOfTapsRequired = 2;
?手指?jìng)€(gè)數(shù)
tap.numberOfTouchesRequired = 2;
二纳鼎、長(zhǎng)按(longPress)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
[imgView addGestureRecognizer:longPress];
[longPress release];
設(shè)置長(zhǎng)按時(shí)間
longPress.minimumPressDuration = 1;
三、旋轉(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(pinchAction:)];
[imgView addGestureRecognizer:pinch];
[pinch release];
五贱鄙、拖拽pan
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
[imgView addGestureRecognizer:pan];
[pan release];
六、輕掃(swipe)
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
默認(rèn)只識(shí)別向右
設(shè)置方向時(shí) 最多只能設(shè)置 水平(左/右)或者垂直(上/下)
swipe.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[imgView addGestureRecognizer:swipe];
[swipe release];
七姨谷、屏幕邊緣拖拽screenEdgePan
UIScreenEdgePanGestureRecognizer *sep = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(sepAction:)];
需要設(shè)置拖拽的邊緣
sep.edges = UIRectEdgeLeft;
[self.view addGestureRecognizer:sep];
[sep release];