Ios Orgin转换后未触发的操作

Ios Orgin转换后未触发的操作,ios,objective-c,uibutton,action,hittest,Ios,Objective C,Uibutton,Action,Hittest,我已设置UITableViewCell,以便您可以向右滑动以显示动作,然后再次向左滑动以隐藏动作。它们被设置在屏幕外,当移动单元格时,单元格orgin会向左移动120像素,以显示控件 问题是一旦被发现并点击,他们就不会开火。这是我的密码 设置我的手机 UISwipeGestureRecognizer *completeSwipeGestureShow = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@s

我已设置UITableViewCell,以便您可以向右滑动以显示动作,然后再次向左滑动以隐藏动作。它们被设置在屏幕外,当移动单元格时,单元格orgin会向左移动120像素,以显示控件

问题是一旦被发现并点击,他们就不会开火。这是我的密码

设置我的手机

        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");
}

我不是100%确定,但可能是这样

由于您是通过调整单元格的边界来移动单元格,这意味着其框架仍在同一位置,只有内容移动到一边。因此,这些触摸仍然被显示的控件阻止,因为它们仍然在细胞的框架内,并且细胞正在处理它们