Animating custom-drawn UITableViewCell when entering edit mode

后端 未结 6 1543
攒了一身酷
攒了一身酷 2020-12-12 09:53

Background

First of all, much gratitude to atebits for their very informative blog post Fast Scrolling in Tweetie with UITableView. The post explains in detail how

6条回答
  •  时光说笑
    2020-12-12 10:15

    For fully control on editing in your custom cell, you should override willTransitionToState method in your UITableViewCell subclass and check state mask

    - (void)willTransitionToState:(UITableViewCellStateMask)state
    {
        NSString *logStr = @"Invoked";
        if ((state & UITableViewCellStateShowingEditControlMask)
            != 0) {
            // you need to move the controls in left
            logStr = [NSString stringWithFormat:@"%@
                      %@",logStr,@"UITableViewCellStateShowingEditControlMask"];
        }
        if ((state & UITableViewCellStateShowingDeleteConfirmationMask)
            != 0) {
            // you need to hide the controls for the delete button
            logStr = [NSString stringWithFormat:@"%@
                      %@",logStr,@"UITableViewCellStateShowingDeleteConfirmationMask"];
        }
        NSLog(@"%@",logStr);
        [super willTransitionToState:state];
    }
    

    also you can override layoutSubviews

    - (void)layoutSubviews {
        // default place for label
        CGRect alarmTimeRect = CGRectMake(37, 7, 75, 30);
        if (self.editing && !self.showingDeleteConfirmation) {
            // move rect in left
            alarmTimeRect = CGRectMake(77, 7, 75, 30);
        }
        [alarmTimeLabel setFrame:alarmTimeRect];
        [super layoutSubviews];
    }
    

提交回复
热议问题