問(wèn)題描述
我在 cellForRowAtIndexPath
UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];[單元格 addGestureRecognizer:gestureR];
它工作正常.但我想要 UISwipeGestureRecognizerDirectionLeft
所以像這樣添加
[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];
當(dāng)我檢查方向和狀態(tài)時(shí),我總是得到 3 = 3
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {NSLog(@"%d = %d",recognizer.direction,recognizer.state);}
如果我只應(yīng)用一個(gè)手勢(shì),它就可以正常工作.我試圖一個(gè)一個(gè)地添加兩個(gè)手勢(shì).但它只會(huì)響應(yīng)一個(gè)手勢(shì).
如何添加第二個(gè)手勢(shì).我直接將一個(gè)手勢(shì)添加到 TableView 另一個(gè)手勢(shì)到單元格,但現(xiàn)在使用.
試試這個(gè)
<上一頁(yè)>UISwipeGestureRecognizer* 手勢(shì)R;手勢(shì)R = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];手勢(shì)R.direction = UISwipeGestureRecognizerDirectionLeft;[查看 addGestureRecognizer:gestureR];手勢(shì)R = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];手勢(shì)R.direction = UISwipeGestureRecognizerDirectionRight;//默認(rèn)[查看 addGestureRecognizer:gestureR];如果您想處理左右滑動(dòng)的不同功能,只需更改選擇器即可.
I added this code in cellForRowAtIndexPath
UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipeFrom:)];
[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];
[cell addGestureRecognizer:gestureR];
it works fine. But I want UISwipeGestureRecognizerDirectionLeft
so Added like this
[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];
When I check with direction and state I am always getting 3 = 3
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"%d = %d",recognizer.direction,recognizer.state);
}
if I apply only one Gesture it works fine. I tried to add two gestures one by one. but it will responding for only one gesture.
How to add second gestures. I added directly to one gesture to TableView another one to cell but now use.
Try this
UISwipeGestureRecognizer* gestureR; gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease]; gestureR.direction = UISwipeGestureRecognizerDirectionLeft; [view addGestureRecognizer:gestureR]; gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease]; gestureR.direction = UISwipeGestureRecognizerDirectionRight; // default [view addGestureRecognizer:gestureR];
If you want to handle different functionalities on left and right swipes, just change the selectors.
這篇關(guān)于如何將滑動(dòng)手勢(shì)添加到 UITableView 單元格?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!