UIView animation for CGAffineTransformMake not working

I have a simple conversion animation that moves a UITableViewCell 70 pixels to the left. In the if part, the animation works just fine, and I get a smooth transition. However, when the function is called again to return the cell to its original position, that is, the else part, I do not get the animation. He just returns to normal, but without animation. How can i fix this?

  if([[slideArray objectAtIndex:indexPath.row] intValue]==0) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.4]; selectedCell.transform=CGAffineTransformMakeTranslation(-70, 0); [UIView commitAnimations]; [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:1]]; } else { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.4]; selectedCell.transform=CGAffineTransformMakeTranslation(0, 0); [UIView commitAnimations]; [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]]; } 
+4
source share
1 answer

try the following animation in a different condition, this will work fine if you have already completed the translation of the if condition.

  [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.4]; selectedCell.transform=CGAffineTransformMakeTranslation(70, 0); [UIView commitAnimations]; [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]]; 

if the above code does not work for you than try the following

 [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:(void (^)(void)) ^{ myImageView.transform=CGAffineTransformMakeTranslation(-70, 0); } completion:^(BOOL finished){ myImageView.transform=CGAffineTransformIdentity; }]; [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]]; 

let me know if there are any problems .. Regards.

+9
source

All Articles