2014-02-05 68 views
0

我正在嘗試將UISwipeGestureRecognizerUITableView混合使用。將UITableView移動到UISwipeGestureRecognizer

我想要做的是,在我做滑動手勢的同時,移動窗口外的UITableView並刷新表格數據。

,我要你用圖像顯示...

這是我的看法:

My View

而且我想獲得這樣的事:

Desired View

當滑動手勢結束時,我可以移動表格,但不是在我做手勢的時候,那是wha我想要。

這是我的代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    swipeToRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(changeToGroup:)]; 
    [swipeToRight setDelegate:self]; 
    [swipeToRight setDirection:UISwipeGestureRecognizerDirectionRight]; 
    [[self table]addGestureRecognizer:swipeToRight]; 

    swipeToLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(changeToContact:)]; 
    [swipeToLeft setDelegate:self]; 
    [swipeToLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    [[self table]addGestureRecognizer:swipeToLeft]; 
} 

- (void)changeToGroup:(UISwipeGestureRecognizer *)swipeGesture 
{ 
    NSLog(@"Right to group"); 
    [self updateTableData]; //Here I move the table and update data. 
    [segmentedControl setSelectedSegmentIndex:0]; 
} 

- (void)changeToContact:(UISwipeGestureRecognizer *)swipeGesture 
{ 
    NSLog(@"Left to contact"); 
    [self updateTableData]; //Here I move the table and update data. 
    [segmentedControl setSelectedSegmentIndex:1]; 
} 

我以爲我可以UIGestureRecognizerStateBegan做到這一點,並稱事件中的動畫,但我不能接受它...

任何人都可以幫助我?

非常感謝!!

回答

0

試試這個,

使用UIPanGestureRecognizer

UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] 
             initWithTarget:self action:@selector(handlePan:)]; 
[recognizer setMaximumNumberOfTouches:1]; 
[recognizer setDelegate:self]; 
[[self table]addGestureRecognizer:recognizer]; 

- (void) handlePan:(UIPanGestureRecognizer *)recognizer { 

    UIView *view = self.tableView; 
    if(recognizer.state == UIGestureRecognizerStateBegan) { 
     // remember where the pan started 
     //panGestureOrigin is a CGPoint variable 
     panGestureOrigin = view.frame.origin; 
     //optional to keep an enum to keep direction 
     //self.panDirection = MenuPanDirectionNone; 
    } 
    CGPoint translatedPoint = [recognizer translationInView:view]; 
     if(translatedPoint.x > 20) { 

      //self.panDirection = MenuPanDirectionRight; 
      [self handleRightPan:recognizer]; 
     } else if(translatedPoint.x < 0) { 

      //self.panDirection = MenuPanDirectionLeft; 
      [self handleLeftPan:recognizer]; 
     } 
} 

- (void) handleRightPan:(UIPanGestureRecognizer *)recognizer { 
    //animate here 

    if(recognizer.state == UIGestureRecognizerStateEnded) { 

     NSLog(@"Right to group"); 
     [self updateTableData]; //Here I move the table and update data. 
     [segmentedControl setSelectedSegmentIndex:0]; 
    } 
} 

- (void) handleLeftPan:(UIPanGestureRecognizer *)recognizer { 
    // animate here 
    if(recognizer.state == UIGestureRecognizerStateEnded) { 
     NSLog(@"Left to contact"); 
     [self updateTableData]; //Here I move the table and update data. 
     [segmentedControl setSelectedSegmentIndex:1]; 
    } 
}