Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView setEditing doesn't animate label constraint change

So, I have a custom tableview cell in tableview and when I set the editing mode on with the [self.tableView setEditing:YES animated:YES]; code.

It sets the editing mode but the problem is that my label on the cell just teleports to it's new location as it is pushed left when the reorder control shows itself. How can I animate the constraint change when the editing happens?

Picture of the my tableview cell:(The right constraint clearly increases when the editing goes on but it's not animated and I want it to be)

Pic1

Edit: Here is my cell's setEditing. I have tried to do it in many ways but the animation just doesn't work for some reason, the change happens instantly.

-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];

    if (editing) {
        [UIView animateWithDuration:0.25f
                              delay:0.0f
                            options:UIViewAnimationOptionCurveEaseIn
                         animations:^{
                             self.labelConstraint.constant = 100;
                             [self layoutIfNeeded];

                         }
                         completion:^(BOOL finished)
         {


         }];
    }
}
like image 615
Samuli Lehtonen Avatar asked Nov 11 '22 15:11

Samuli Lehtonen


1 Answers

Worked for me if I change constraint before animation block

- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [self layoutIfNeeded];
    self.containerLeftConstraint.constant = editing ? EditingIndent : 0.0f;

    [UIView animateWithDuration:0.3
                     animations:^{

                         [self layoutIfNeeded];
                     }];

}
like image 165
Peter K Avatar answered Nov 15 '22 04:11

Peter K