Animated text label in uitableviewcell using willTransitionToState

I am trying to animate a text label in a UItableviewcell when I click the edit button. I try to make it fade and fade. fade in, but when I click "edit", the text label disappears, and when I click "done", I just disappear.

Can someone tell me why it is not working?

early

- (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]; } } 
+6
iphone
source share
2 answers

I noticed that when entering willTransitionToState the animation is disabled. After that fixed.

 - (void)willTransitionToState:(UITableViewCellStateMask)state { [super willTransitionToState:state]; //Should be enabled by default...but apparently not [UIView setAnimationsEnabled:YES]; ... } 
+12
source share

From everything I read, I thought for sure that theTransitionToState path is a path. It even works great if you use didTransitionToState, although the transition starts after normal editing is complete.

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]; } } 
+6
source share

All Articles