I have not done much animation, and I need some help with this. I have a tabBarController as my root controller, and I want to have another tabBarController, and I want to bring it up as a Modal View Controller, and I have a problem with the animation.
There are currently four animations for modalViewControllers, namely
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
I want a different animation – slide from the right to the left. – How can I do this animation?
Any help with this?
Edit:
My idea to push a tabBarController onto the navigation stack sucks! Apple’s comment on this approach:
You never want to push a tab bar controller onto the navigation stack of a navigation controller. Doing so creates an unusual situation whereby the
tab bar appears only while a specific view controller is at the top of the navigation stack. Tab bars are designed to be persistent, and so this transient approach can be confusing to users.
I am out of ideas. Someone help me with the animation for modal view controllers.
You could write the animation code manually. Here are the general steps:
UIViewController(essentially a dud controller to house yourUITabBarController) – I usually call thisShellViewController.ShellViewController‘sinitmethod (whichever one you would use), set itsframeoutside of the screen to the right, e.g.[self.view setFrame:CGRectMake(320, 0, 320, 480)];ShellViewController- (void)presentSelf- (void)dismissSelfShellViewControllerwhen you want to present yourUITabBarControllerUITabBarControllerinstance inside of theShellViewControllerinstance[currentView addSubview:shellViewController.view];ShellViewControllerhousing yourUITabBarControllerHere is the code for animating-in (e.g. the
- (void)presentSelfmethod):Here is the code for animating-out (e.g. the
- (void)dismissSelfmethod):Keep in mind that these animation methods do only that: animate. They don’t disable interaction with the current view nor with the
ShellViewController‘s view/subviews which are being animated in/out. You’ll need to manually disable user interaction during animation and then reinstate it after the animation is finished. There is aUIViewmethod that performs a selector when animation is finished:You can put this right after the
[UIView setAnimationDelegate:self]in each animation block above. Of course, you would need to write theenableUserInteractionmethod yourself… anddisableUserInteractionmethod for that matter.It is a hassle to go this route, but it works. Once you get the
ShellViewControllerwritten up, it makes for a nice reusable snippet.