I currently have a view that is contained on a view. The main view controller (parent view) has a property that is hooked up in interface builder to the subview. The subview contains a button. I want the button to flip the subview while keeping the main view stationary. I currently have the following code in my IBAction for the button:
[UIView transitionWithView: self.subViewFront
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
animations: nil
completion: nil];
[UIView commitAnimations];
[[self view] addSubview: self.subViewBack;
This code works great, however I noticed the following when looking at the API reference from Apple:
Use of the methods in this section is discouraged in iOS 4 and later.
Use the block-based animation methods instead.
Following this advice I attempted to use the following code:
[UIView transitionFromView: self.subViewFront
toView: self.subViewBack
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
completion: nil];
It looks like it should do the same as what I originally coded, however, when I run my app with this code, it flips my entire view (parent and child view) instead of just the subview. Should this method be used as a substitution from the original method I have used, or is there something I’m missing? Thanks.
I had the same issue (with the parent getting animated instead), but resolved it by adding the two views (
subViewFrontandsubViewBack) to a container view instead.So add your two views to a container
UIViewinstead, then use the-transitionFromView:...just like your example says: