Help in animating iPhone Modal View

I don’t have much animation and I need help. I have a tabBarController as my root controller, and I want to have another tabBarController , and I want to display it as a Modal View Controller, and I have an animation problem.

There are currently four animations for modalViewControllers , namely

 typedef enum { UIModalTransitionStyleCoverVertical = 0, UIModalTransitionStyleFlipHorizontal, UIModalTransitionStyleCrossDissolve, UIModalTransitionStylePartialCurl, } UIModalTransitionStyle; 

I need another animation - a slide from right to left. - How can I make this animation?

Any help with this?


Edit:

My idea is to push tabBarController on the navigation stack, sucks! Apple will comment on this approach:

You never want to push the tab bar controller onto the navigation stack of the navigation controller. This creates an unusual situation in which the tab bar appears only when a specific view controller is at the top of the navigation stack. Dashboards are designed to work continuously, and therefore this transitional approach can be confusing for users.

I am out of ideas. Someone is helping me with animations for modal controllers.

+4
source share
3 answers

You can write the animation code manually. Here are the basic steps:

  • Create a subclass of UIViewController (basically a dud controller to host your UITabBarController ). I usually call this a ShellViewController .
  • In the ShellViewController init method (depending on which one you use) set its frame off-screen to the right, for example. [self.view setFrame:CGRectMake(320, 0, 320, 480)];
  • Create two methods in ShellViewController
    • - (void)presentSelf
    • - (void)dismissSelf
  • Create an instance of ShellViewController if you want to present your UITabBarController
  • Place an instance of UITabBarController inside an instance of ShellViewController
  • Call [currentView addSubview:shellViewController.view];
  • Use the methods above to submit and release the ShellViewController enclosure of your UITabBarController
  • A deal with memory management as your business logic dictates

Here is the code for the animation (for example, the method - (void)presentSelf ):

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.15]; //the double represents seconds [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; [[self view] setFrame:CGRectMake(0, 0, 320, 480)]; [UIView commitAnimations]; 

Here is the code for the animation (for example, the method - (void)dismissSelf ):

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.15]; [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; [[self view] setFrame:CGRectMake(320, 0, 320, 480)]; [UIView commitAnimations]; 

Keep in mind that these animation methods do only the following: aimate. They do not disable interaction with the current view, as well as with ShellViewController view / subviews, which are animated to / from. You will need to manually disable user interaction during the animation, and then restore it after the animation finishes. There is a UIView method that executes the selector when the animation is complete:

 [UIView setAnimationDidStopSelector:@selector(enableUserInteraction)]; 

You can put this right after [UIView setAnimationDelegate:self] in each animation block above. Of course, you need to write the enableUserInteraction method yourself ... and disableUserInteraction , if that is true.

It is not easy to go this route, but it works. After you ShellViewController , it will make a good reusable snippet.

+4
source

Insert the root panel controller into the UINavigationController. If this does not allow you, stick with the UIViewController in between (which does: UINavigationController injects the UIViewController into which the UITabBarControllers view is added). Its nasty-bad, but it should (!) Work.

+1
source

Modular view controllers do not move, because this is a standard stack animation (clicking or popping). This confuses users. If this is modal, you really have to shift it from the bottom or do a flip or something like that.

Why do you need a tab bar in a modal view? Typically, modal representations are used for things like data entry, sound reproduction, etc. HIG tab bar states: β€œIn general, use the tab bar to organize information at the application level.” Having a tab bar in a modular view controller violates this. Of course, you do not have to follow all the recommendations in HIG, but this is the case when you really should follow the recommendations of Apple.

Can you tell us more about your specific use case so that we can make suggestions on what might be the right solution? Perhaps segmented control is more appropriate?

0
source

All Articles