uigesturerecognizer是手勢的基類,定義了所有手勢的基本行為。其它均為它的子類。
uitapgesturerecognizer
uipinchgesturerecognizer
uirotationgesturerecognizer
uiswipegesturerecognizer
uipangesturerecognizer
uilongpressgesturerecognizer
都繼承自uigesturerecognizer,它們都具有相同的基本行為,但在具體上又有所不同。
以下是這些手勢的**實現:
1.先對各個手勢進行建立以及一些引數的設定:
//--------單擊,雙擊-----------
uitapgesturerecognizer *singletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tap:)];
[self.view addgesturerecognizer:singletap];
uitapgesturerecognizer *doubletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tap:)];
doubletap.numberoftapsrequired = 2;//預設為1
[self.view addgesturerecognizer:doubletap];
[singletap requiregesturerecognizertofail:doubletap];
//--------輕掃------------
uiswipegesturerecognizer *swipegesture = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(swipe:)];
swipegesture.direction = uiswipegesturerecognizerdirectionup;
[self.view addgesturerecognizer:swipegesture];//預設向右
//--------滑動------------
uipangesturerecognizer *pangesture = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(pan:)];
[self.view addgesturerecognizer:pangesture];
//--------長按------------
uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(longpress:)];
longpress.minimumpressduration = 3;//預設為0.5
[self.view addgesturerecognizer:longpress];
//--------旋轉------------
uirotationgesturerecognizer *rotationgesture = [[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(rotation:)];
[self.view addgesturerecognizer:rotationgesture];
2.各個手勢觸發時呼叫的相應方法:
-(void)tap:(uitapgesturerecognizer *) tap
else if (tap.numberoftapsrequired==2)
else//不能識別多擊 }
-(void)swipe:(uiswipegesturerecognizer *) swipegesture
-(void)pan:(uipangesturerecognizer *)pangesture
-(void)longpress:(uilongpressgesturerecognizer *)longpressgesture
-(void)rotation:(uirotationgesturerecognizer *)rotation
總結:ios中各個手勢其實是由事件構成,而基本事件都具有相應的處理方法,例如開始觸控,正在移動,手指離開螢幕時都會呼叫相應的方法,而手勢正是將這些相應的處理方法進行了集合。
js基本事件
js基本事件 屬性 當以下情況發生時,出現此事件 ff n ie onabort 影象載入被中斷13 4onblur 元素失去焦點12 3onchange 使用者改變域的內容12 3onclick 滑鼠點選某個物件12 3ondblclick 滑鼠雙擊某個物件14 4onerror 當載入文件或影象...
jQuery的基本事件與繫結事件
一 基礎事件包括滑鼠事件,鍵盤事件,windows事件,和表單事件。復合事件有滑鼠連擊事件和游標懸停事件。二 滑鼠在子元素進出時候,mouse over 事件會被觸發,而mouse enter 則不會被觸發。三 按下鍵盤時keydown,四 繫結事件bind type,data fn 分為事件型別,...
python事件迴圈 如何實現基本事件迴圈?
python 您可以檢視twisted reactor的實現,它可能是python中事件迴圈的最佳實現。twisted中的reactor是介面的實現,您可以指定要執行的reactor型別 select epoll kqueue 都基於使用這些系統呼叫的c api 還有基於qt和gtk工具包的reac...