2013-04-08 25 views
2

我正在使用自定義UITableViewCell子類的UITableView的自定義滑動事件。我包括我的頭的UIGestureRecognizerDelegate,並有這viewDidLoad:UITableView滑動手勢需要接近完美的準確度

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; 
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; 
swipeLeft.numberOfTouchesRequired = 1; 
[self.tableView addGestureRecognizer:swipeLeft]; 

我swipeLeft方法看起來像這樣:

-(void)didSwipe:(UISwipeGestureRecognizer *)recognizer { 

    if (recognizer.state == UIGestureRecognizerStateEnded) 
    { 
     CGPoint swipeLocation = [recognizer locationInView:self.tableView]; 
     NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation]; 
     NSDictionary *clip = [self.clips objectAtIndex:swipedIndexPath.row]; 
     NSLog(@"Swiped!"); 


    } 
} 

這是工作的排序,但刷卡必須是相當精確的。像幾乎不可能的精確。

我幾乎是通過使用UIPanGestureRecognizer來代替它,但不幸的是,它對於使用全局平移手勢識別器(對於那些感興趣的ECSlidingViewController)的全局側抽屜組件來說並不好。

有沒有辦法解決這個問題?任何幫助將不勝感激,因爲我一直在搜索和瀏覽幾個小時尋找解決方案。

+0

所以是用戶在特定單元格上還是在桌面視圖本身上滑動的點? – MishieMoo 2013-04-08 22:43:31

+0

@MishieMoo一個單元格,但我認爲在整個tableview上實現GR更好,並使用CG點來獲取被刷過的單元格。 – 2013-04-08 22:47:51

+0

作爲一個方面說明,我確實嘗試並將其應用於一個單元格,但我遇到了完全相同的問題。 – 2013-04-08 22:59:15

回答

8

正如在Twitter指出的Kolin Krewinkel,實施這些2種委託方法確實起作用:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{ 
    return YES; 
} 

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 
{ 
    return YES; 
} 
+0

這最初爲我工作,但在爲我的tableview創建子類之後,我還必須在我所有的tableview的預先存在的識別器上調用requireGestureRecognizerToFail。否則,垂直和水平識別器會相互干擾。希望可以節省一些時間! – arsenius 2013-11-07 03:14:12

0

我所用的ECSlidingViewController和滑動到刪除一個UITableView(頂視圖具有類似的問題控制器在我的情況下向左滑動顯示菜單)。

我加入了代表對我ECSlidingViewController這樣的默認panGesture屬性只在菜單拉固定的問題,如果輕掃在屏幕的最右側邊緣開始:

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 
{ 
    if ([gestureRecognizer locationInView:gestureRecognizer.view].x > ([UIScreen mainScreen].bounds.size.width - 60.0)) 
    { 
    return YES; 
    } 
return NO; 
}