Animating custom-drawn UITableViewCell when entering edit mode

后端 未结 6 1560
攒了一身酷
攒了一身酷 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:20

    I just had this question too: how to animate a custom editing mode? I didn't really like the solution here, so I decided to think a little bit and found a different solution. I don't know if it's better, but I prefer that one. So I decided to share it here:

    In the custom cell (inherit from UITableViewCell), just overload the setEditing:

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
        [super setEditing:editing animated:animated];
    
        if (animated) {
            [UIView beginAnimations:@"setEditingAnimation" context:nil];
            [UIView setAnimationDuration:0.3];
        }
    
        if (editing) {
            /* do your offset and resize here */
        } else {
            /* return to the original here*/
        }
    
        if (animated)
            [UIView commitAnimations];
    }
    

    I don't check if the editing value is the same, but that's just an idea how I did it.

提交回复
热议问题