2013-07-10 41 views
0

我有我的UITableViewCell設置,以便您可以向右滑動以顯示動作,然後再向左滑動以隱藏它們。它們被設置在屏幕外,當單元格被滑動時,單元格或者元素左移-120px以顯示控件。Orgin轉換後沒有觸發動作

問題是,他們沒有解僱一旦泄露,並點擊。這是我的代碼。

設置我的手機

 UISwipeGestureRecognizer *completeSwipeGestureShow = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showCompleteControl:)]; 
     UISwipeGestureRecognizer *completeSwipeGestureHide = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(hideCompleteControl:)]; 

     completeSwipeGestureShow.direction = UISwipeGestureRecognizerDirectionRight; 
     completeSwipeGestureHide.direction = UISwipeGestureRecognizerDirectionLeft; 

     UIView *cellControlDone = [[UIView alloc] initWithFrame:CGRectMake(-60, 0, 60, 127)]; 
     UIView *cellControlDelete = [[UIView alloc] initWithFrame:CGRectMake(-120, 0, 60, 127)]; 

     cellControlDone.backgroundColor = [UIColor colorWithRed:(36.0/255.0) green:(195.0/255.0) blue:(28.0/255.0) alpha:1.0]; 
     cellControlDelete.backgroundColor = [UIColor colorWithRed:(236.0/255.0) green:(1.0/255.0) blue:(1.0/255.0) alpha:1.0]; 

     UIButton *cellControlDoneIcon = [UIButton buttonWithType:UIButtonTypeCustom]; 
     UIButton *cellControlDeleteIcon = [UIButton buttonWithType:UIButtonTypeCustom]; 

     [cellControlDoneIcon setBackgroundImage:[UIImage imageNamed:@"Done.png"] forState:UIControlStateNormal]; 
     [cellControlDeleteIcon setBackgroundImage:[UIImage imageNamed:@"Delete.png"] forState:UIControlStateNormal]; 

     cellControlDoneIcon.frame = CGRectMake(((60 - 22)/2), ((127 - 22)/2), 22, 22); 
     cellControlDeleteIcon.frame = CGRectMake(((60 - 22)/2), ((127 - 22)/2), 22, 22); 

     [cellControlDoneIcon addTarget:self action:@selector(completeTask) forControlEvents:UIControlEventTouchUpInside]; 
     [cellControlDeleteIcon addTarget:self action:@selector(cancelTask) forControlEvents:UIControlEventTouchUpInside]; 

     [cellControlDone addSubview:cellControlDoneIcon]; 
     [cellControlDelete addSubview:cellControlDeleteIcon]; 

     [cell addSubview:cellControlDone]; 
     [cell addSubview:cellControlDelete]; 

     cell.clipsToBounds = YES; 

     [cell addGestureRecognizer:completeSwipeGestureShow]; 
     [cell addGestureRecognizer:completeSwipeGestureHide]; 

的操作

- (void) showCompleteControl:(UISwipeGestureRecognizer *)gesture 
{ 
    CGPoint location = [gesture locationInView:tableView]; 
    NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location]; 
    UITableViewCell *swipedCell = [tableView cellForRowAtIndexPath:swipedIndexPath]; 

    [UIView animateWithDuration:0.25 
     delay:0.0 
     options: UIViewAnimationCurveEaseOut 
     animations:^{ 
      [swipedCell setBounds:CGRectMake(-120, 0, 320, 127)]; 
      NSArray* subviews = [swipedCell.contentView subviews]; 
      for (UIView* subview in subviews) { 
       if(subview.tag == 9999) 
       { 
        subview.frame = CGRectMake(0, 126, 10, 1); 
        subview.backgroundColor = [UIColor colorWithRed:(224.0/255.0) green:(224.0/255.0) blue:(224.0/255.0) alpha:1.0]; 
       } 
      } 
     } 
     completion:^(BOOL finished){ 
      // Do nothing 
     } 
    ]; 
} 

- (void) hideCompleteControl:(UISwipeGestureRecognizer *)gesture 
{ 
    CGPoint location = [gesture locationInView:tableView]; 
    NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location]; 
    UITableViewCell *swipedCell = [tableView cellForRowAtIndexPath:swipedIndexPath]; 

    [UIView animateWithDuration:0.25 
     delay:0.0 
     options: UIViewAnimationCurveEaseOut 
     animations:^{ 
      [swipedCell setBounds:CGRectMake(0, 0, 320, 127)]; 
      NSArray* subviews = [swipedCell.contentView subviews]; 
      for (UIView* subview in subviews) { 
       if(subview.tag == 9999) 
       { 
        subview.frame = CGRectMake(0, 0, 10, 127); 
        subview.backgroundColor = [UIColor colorWithRed:(124.0/255.0) green:(124.0/255.0) blue:(124.0/255.0) alpha:1.0]; 
       } 
      } 
     } 
     completion:^(BOOL finished){ 
      // Do nothing 
     } 
    ]; 
} 

- (void) completeTask 
{ 
    NSLog(@"Task Complete"); 
} 

- (void) cancelTask 
{ 
    NSLog(@"Task Canceled"); 
} 

回答

0

我不是100%肯定,但它可能是這...

既然你通過調整邊界來移動單元格,這意味着它的框架仍然在同一個地方,只有內容在移動 在旁邊。所以觸摸仍然被阻擋在顯示控制之下,因爲它們仍然在單元格的框架內,並且正在處理它們。