Orgin过渡后动作未触发

时间:2013-07-10 19:19:27

标签: ios objective-c uibutton action hittest

我设置了UITableViewCell,以便您可以向右滑动以显示操作,然后再向左滑动以隐藏它们。它们被设置在屏幕外,当细胞被刷过时,细胞orgin向左转移-120px以显示对照。

问题是他们一旦被揭发就不会被解雇,然后点击。这是我的代码。

设置我的手机

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

1 个答案:

答案 0 :(得分:0)

我不是百分百确定,但可能是这个......

由于您通过调整其边界来移动单元格,这意味着它的框架仍在同一个位置,只有内容移动到一边。所以触摸仍然被屏蔽控件阻挡,因为它们仍然在单元格的框架内并正在处理它们。