常見手勢新增

2021-06-27 16:54:59 字數 3408 閱讀 7189

@synthesize imageview;

cgfloat lastscalefactor=1;//放大、縮小

cgfloat  netrotation;//旋轉

cgpoint nettranslation;//平衡

nsarray *images;//陣列

int imageindex=0;//陣列下標

- (void)viewdidload

//雙擊螢幕時會呼叫此方法,放大和縮小

-(ibaction)handletapgesture:(uigesturerecognizer*)senderelse

}//捏的手勢,使放大和縮小,捏的動作是乙個連續的動作

-(ibaction)handlepinchgesture:(uigesturerecognizer*)senderelse

//狀態是否結束,如果結束儲存資料

if(sender.state==uigesturerecognizerstateended)else}}

//旋轉手勢

-(ibaction)handlerotategesture:(uigesturerecognizer*)sender

}//拖手勢

-(ibaction)handlepangesture:(uigesturerecognizer*)sender

}//划動手勢

-(ibaction)handleswipegesture:(uigesturerecognizer*)sender

//得到不越界不<0的下標

imageindex=(imageindex<0)?([images count]-1):imageindex%[images count];

//imageview顯示

imageview.image=[uiimage imagenamed:[images objectatindex:imageindex]];

}//長按手勢

-(ibaction)handlelongpressgesture:(uigesturerecognizer*)sender

-(void)dealloc

==========================================

[**] 乙個手指,拍擊兩次手勢

uitapgesturerecognizer *onefingertwotaps =

[[[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(onefingertwotaps)] autorelease];

// set required taps and number of touches

[onefingertwotaps setnumberoftapsrequired:2];

[onefingertwotaps setnumberoftouchesrequired:1];

// add the gesture to the view

[[self.view] addgesturerecognizer:onefingertwotaps];

//訊息方法onefingertwotaps

- (void)onefingertwotaps

[**] 2個手指,拍擊兩次手勢

uitapgesturerecognizer *twofingerstwotaps =

[[[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(twofingerstwotaps)] autorelease];

[twofingerstwotaps setnumberoftapsrequired:2];

[twofingerstwotaps setnumberoftouchesrequired:2];

[[self view] addgesturerecognizer:twofingerstwotaps];

// 向上滑動

uiswipegesturerecognizer *onefingerswipeup =

[[[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(onefingerswipeup:)] autorelease];

[onefingerswipeup setdirection:uiswipegesturerecognizerdirectionup];

[[self view] addgesturerecognizer:onefingerswipeup];

- (void)onefingerswipeup:(uiswipegesturerecognizer *)recognizer

// 向下滑動

uiswipegesturerecognizer *onefingerswipedown =

[[[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(onefingerswipedown:)] autorelease];

[onefingerswipedown setdirection:uiswipegesturerecognizerdirectiondown];

[[self view] addgesturerecognizer:onefingerswipedown];

- (void)onefingerswipedown:(uiswipegesturerecognizer *)recognizer

[**] 2個手指,旋轉  (這個還沒怎麼理解,與捏合有什麼區別)

uirotationgesturerecognizer *twofingersrotate =

[[[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(twofingersrotate:)] autorelease];

[[self view] addgesturerecognizer:twofingersrotate];

- (void)twofingersrotate:(uirotationgesturerecognizer *)recognizer

[**] 2個手指,捏合

uipinchgesturerecognizer *twofingerpinch =

[[[uipinchgesturerecognizer alloc] initwithtarget:self action:@selector(twofingerpinch:)] autorelease];

[[self view] addgesturerecognizer:twofingerpinch];

- (void)twofingerpinch:(uipinchgesturerecognizer *)recognizer

新增手勢控制

構建手勢探測器 gesturedetector mygesture new gesturedetector activity,this private static final int fling min distance 120 移動最小距離 private static final int fl...

給手勢新增tag值

1 定義乙個tap手勢,uitapgesturerecognizer tap uitapgesturerecognizer alloc initwithtarget self action selector evetap 2 通過uiview給手勢設定tag值 uiview tapview tap ...

IOS常見事件 手勢的應用

往viewcontroller.xib檔案裡拖動乙個imageview,並使覆蓋整個螢幕,改動屬性為 viewcontroller.h檔案 import inte ce viewcontroller uiviewcontroller property nonatomic,retain iboutle...