6

I am trying to animate the textlabel in a UItableviewcell when I press the edit button. I am trying to make it fade out and fade in. fading in works but when I press 'edit' the textlabel disappears and when I press on 'done' I fades in just perfectly.

Can anyone tell me why it isn't working?

thanks in advance

- (void)willTransitionToState:(UITableViewCellStateMask)state {
 [super willTransitionToState:state];

 if ((state & UITableViewCellStateEditingMask) || (state & UITableViewCellStateShowingDeleteConfirmationMask)) {
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.3];
  label.alpha = 0.0;
  [UIView commitAnimations];
 }
}

- (void)didTransitionToState:(UITableViewCellStateMask)state {
 [super didTransitionToState:state];

 if (!(state & UITableViewCellStateEditingMask) && !(state & UITableViewCellStateShowingDeleteConfirmationMask)) {
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.5];
  label.alpha = 1.0;
  [UIView commitAnimations];
 }
}

2 Answers 2

12

I noticed that when entering willTransitionToState that animations were disabled. The following fixed it.

- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    [super willTransitionToState:state];

    //Should be enabled by default...but apparently not
    [UIView setAnimationsEnabled:YES];
...
}
1
  • 3
    You don't know why they may have the animations disabled so you might want to save the value returned by +[UIView areAnimationsEnabled] before your animation block and restore the value at the end of the method.
    – Alej
    Nov 11, 2011 at 5:49
6

From everything I had read I thought for sure the willTransitionToState was the way to go. It even works perfectly if you use didTransitionToState though the transition starts after the normal editing transition finishes.

As it turns out I think you want to use setEditing

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

    if(editing) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.3];
        label.alpha = 0.0;
        [UIView commitAnimations];
    } else {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.3];
        label.alpha = 1.0;
        [UIView commitAnimations];
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.