iOS 手勢識別 拖動 旋轉 捏合

2021-08-07 01:43:37 字數 933 閱讀 8563

1.平移    

uipangesturerecognizer *pan = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(pan:)];

新增手勢

[self.imagev addgesturerecognizer:pan];

實現手勢方法

手指在螢幕上移動進呼叫

- (void)pan:(uipangesturerecognizer *)pan

2.旋轉

新增旋轉手勢

uirotationgesturerecognizer *rotation = [[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(rotation:)];

設定**,設定**的目的就讓它能夠同時支援旋轉跟縮放

rotation.delegate = self;

新增手勢

[self.imagev addgesturerecognizer:rotation];

當旋轉時呼叫

- (void)rotation:(uirotationgesturerecognizer *)rotation

3.新增縮放手勢

新增縮放手勢

uipinchgesturerecognizer *pinch = [[uipinchgesturerecognizer alloc] initwithtarget:self action:@selector(pinch:)];

[self.imagev addgesturerecognizer:pinch];

縮放手勢時呼叫

-(void)pinch:(uipinchgesturerecognizer *)pinch

iOS 手勢識別

首先給大家解釋一下為什麼要學習手勢識別?如果想監聽乙個uiview上面的觸控事件,之前的做法是 自定義乙個uiview 實現uiview的touches方法,在方法裡面實現具體功能 透過touches監聽uiview的觸控事件,有很明顯的幾個缺點 1.必須要自定義uiview,2.由於是在view內...

iOS手勢識別初探

uigesturerecognizerstate的定義如下 typedef ns enum nsinteger,uigesturerecognizerstate uigesturerecognizerstatepossible 預設狀態,手勢識別器尚未識別出手勢,但是可能已經在處理觸屏事件了。uig...

iOS各種手勢識別

import viewcontroller.h inte ce viewcontroller property nonatomic,strong uiimageview imageview end implementation viewcontroller synthesize imageview ...