UIView transition animation does not work with transitionWithView: duration: options: animations: completion method

On iOS, documentation using beginAnimation-commitAnimation is not recommended. So, for animations and transitions, there are new methods that use ^ blocks. However, when I use transitionWithView: duration: options: animations: completion method, I don't get any transition effects. Therefore, if I write:

[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; firstView.hidden = YES; secondView.hidden = NO; [UIView commitAnimations]; 

it works, but if I do it as follows

 [UIView transitionWithView:self.view duration:1.0 options UIViewAnimationCurveEaseIn|UIViewAnimationTransitionCurlUp animations:^{ firstView.hidden = YES; secondView.hidden = NO; } completion:NULL ]; 

I do not get any transition effects. What am I missing?

+6
source share
1 answer

OK, I found subtle details that everyone should consider in order for animations and transitions to work with the method available in iOS 4 and later. When specifying animation / transition parameters for this method, we must use constants with the word "Option" in it. Therefore, instead of writing

 UIViewAnimationCurveEaseIn|UIViewAnimationTransitionCurlUp 

we must write

 UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionTransitionCurlUp 

after fixing that the transition worked just fine

+18
source

Source: https://habr.com/ru/post/897590/


All Articles