Reputation: 1158
I'm following Apple's guide to build my own custom container view controller. It seems to work just fine out of the box, except for one irritating problem.
How exactly do I specify at which time my child view controller will receive viewWillAppear:
and viewDidAppear:
calls (and their disappear
counterparts)?
Let's say I have a fancy animation of a child sliding into the parent or something like that. Quite naturally, I'd like viewWillAppear:YES
to be called at the beginning of the animation and viewDidAppear:YES
at the end. However, by default both viewWillAppear:NO
and viewDidAppear:NO
are called at the same time upon my child's view being added to parent's view.
Now, I know there are beginAppearanceTransition:animated:
and endAppearanceTransition
methods, added in iOS 6, but I'd like to support iOS 5. It also seems like they are meant to be used in advanced cases:
Once you add a child to a container, the container automatically forwards rotation and appearance callbacks to the child view controllers as soon as an event occurs that requires the message to be forwarded. This is normally the behavior you want, because it ensures that all events are properly sent. However, sometimes the default behavior may send those events in an order that doesn’t make sense for your container. For example, if multiple children are simultaneously changing their view state, you may want to consolidate the changes so that the appearance callbacks all happen at the same time in a more logical order. To do this, you modify your container class to take over responsibility for appearance or rotation callbacks.
There's also transitionFromViewController:toViewController:duration:options:animations:completion:
method which calls appearance methods at appropriate times, but it requires two view controllers in action and generally looks out of place here. Of course, I may do the trick and feed it a dummy child, but seriously...
Is there anything I'm missing? Any help would be greatly appreciated.
Upvotes: 4
Views: 903
Reputation: 1158
And the answer is kinda amusing.
The docs may say that beginAppearanceTransition:animated:
and endAppearanceTransition
are available in iOS 6+, but that's not true. These methods are just fine to use in iOS 5 as well:
- (void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
- (void)endAppearanceTransition __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
This question's answer also states the same thing. Case solved!
Upvotes: 3