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

1

6

In iOS Documentation usage of beginAnimation-commitAnimation is discouraged. So for animations and transitions there are new methods that make use of ^blocks. However when I use transitionWithView:duration:options:animations:completion method I get no transition effects.So 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 the following way

[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?

Platelet answered 19/9, 2011 at 6:28 Comment(0)
P
18

OK, I've found the subtle detail everyone needs to take note of in order to get the animation and transitions work with the method available in iOS 4 and later.When specifying the animation/transition options for the method we must use the constants with the word "Option" in it. So instead of writing

UIViewAnimationCurveEaseIn|UIViewAnimationTransitionCurlUp

we should write

UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionTransitionCurlUp

after fixing that the transition worked just fine

Platelet answered 20/9, 2011 at 4:35 Comment(3)
Ha, nice spot, and easy mistake to make with autocompletion... where is type safety when you need it!Hecatomb
Oh my GOD! I spent two frustrating hours on this crap until I found this. Apple seriously needs to depreciate the "non-option" versions.Ragwort
As a result I decided to set the build setting CLANG_WARN_ENUM_CONVERSION to YES from now on.Shull

© 2022 - 2024 — McMap. All rights reserved.