觸控手勢識別2

2021-06-26 17:34:50 字數 3721 閱讀 7199

// 1. 點按手勢

uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tap:)];

// 點按次數,例如雙擊2

// 注意:在ios中最好少用雙擊,如果一定要用,就一定要有乙個圖形化的介面告知使用者可以雙擊

[tap setnumberoftapsrequired:2];

// 用幾根手指點按

[tap setnumberoftouchesrequired:1];

[imageview addgesturerecognizer:tap];

// 2. 長按手勢 long press

uilongpressgesturerecognizer *longtap = [[uilongpressgesturerecognizer alloc]initwithtarget:self action:@selector(longtap:)];

[imageview addgesturerecognizer:longtap];

// 3. 拖動手勢 pan

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

[imageview addgesturerecognizer:pan];

// 4. 旋轉手勢 rotation

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

[imageview addgesturerecognizer:rotation];

// 5. 縮放(捏合)手勢 pinch

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

[imageview addgesturerecognizer:pinch];

// 6. 輕掃手勢 swipe

/*手指在螢幕上掃動,和拖動手勢的區別在於,手指離開螢幕才會觸發監聽方法

1> 手指可以上、下、左、右四個方向輕輕掃動,如果沒有指定方向,預設都是向右掃動

2> 在設定輕掃手勢時,通常需要將手勢識別新增到父檢視上監聽

3> 在監聽方法中,注意不要使用recognizaer.view,因為手勢監聽的是父檢視,而要處理的檢視通常是其他的檢視

如果要使用多個方向的輕掃手勢,需要指定多個輕掃手勢,通常只需指定左右兩個方向即可。

因為ios使用者大多不習慣上下的輕掃動作

*/uiswipegesturerecognizer *swipe1 = [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(swipe:)];

[swipe1 setdirection:uiswipegesturerecognizerdirectionup];

[self.view addgesturerecognizer:swipe1];

uiswipegesturerecognizer *swipe2 = [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(swipe:)];

[swipe2 setdirection:uiswipegesturerecognizerdirectiondown];

[self.view addgesturerecognizer:swipe2];

uiswipegesturerecognizer *swipe3 = [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(swipe:)];

[swipe3 setdirection:uiswipegesturerecognizerdirectionleft];

[self.view addgesturerecognizer:swipe3];

uiswipegesturerecognizer *swipe4 = [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(swipe:)];

[swipe4 setdirection:uiswipegesturerecognizerdirectionright];

[self.view addgesturerecognizer:swipe4];

#pragma mark - 手勢監聽方法

#pragma mark 輕掃手勢

// 儘管輕掃手勢也是連續手勢,但是該手勢是在手指離開螢幕才會被觸發的

// 因此,在編寫**時,不需要處理手勢的狀態

- (void)swipe:(uiswipegesturerecognizer *)recognizer

else if (uiswipegesturerecognizerdirectiondown == recognizer.direction) else if (uiswipegesturerecognizerdirectionleft == recognizer.direction) else

[uiview animatewithduration:1.0 animations:^ completion:^(bool finished) ];

}];}#pragma mark 捏合手勢

- (void)pinch:(uipinchgesturerecognizer *)recognizer

else if (uigesturerecognizerstateended == recognizer.state) ];

}}#pragma mark 旋轉手勢,至少兩根手指

- (void)rotation:(uirotationgesturerecognizer *)recognizer

else if (uigesturerecognizerstateended == recognizer.state) ];

}}#pragma mark 拖動手勢

- (void)pan:(uipangesturerecognizer *)recognizer

else if (uigesturerecognizerstateended == recognizer.state) ];

}}#pragma mark 長按手勢

- (void)longtap:(uilongpressgesturerecognizer *)recognizer

completion:^(bool finished) ];

} else if (uigesturerecognizerstateended == recognizer.state) completion:^(bool finished) ];

}}#pragma mark 點按手勢

- (void)tap:(uitapgesturerecognizer *)recognizer

completion:^(bool finished) ];

}

windows觸控手勢

觸控板手勢 簡而言之,在這篇文章裡,觸控手勢1到4可以在任何一種觸控板上使用,而手勢5到8則需要精確觸控板。1.拖拽 要模擬滑鼠的拖拽功能,只需要將乙個手指在某個專案上輕輕的雙擊一下,然後就可以拖拽它了。當拖拽到需要的位置時抬起指尖,就可以把這個專案放置到所在的地方。2.滾屏 3.縮放 要模擬在大多...

簡單的多點觸控手勢演算法

簡單的多點觸控手勢演算法 1.zoom動作 1 檢測到雙指down事件,記錄此時雙指間的距離為olddistant 2 當雙指移動時,實時計算雙指間的距離sampledistant 3 計算出縮放比例 zoom sampledistant olddistant 4 重複第2,3步直到up事件發生。2...

在 Mac 上使用多點觸控手勢

使用多點觸控觸控板或妙控滑鼠,您可以通過輕點 輕掃 捏合或開合一根或多根手指進行有用的操作。有關這些手勢的更多資訊,請選取蘋果選單 系統偏好設定 然後點按 觸控板 您可以關閉某個手勢,更改手勢型別,以及了解哪些手勢可在您的 mac 上使用。輕點來點按 用單指輕點來進行點按。輔助點按 右鍵點按 用雙指...