Flip complete UITabView on the iPhone - iphone

I have a TabView based application on the iPhone. On initial loading, I want to flip-animate the screen for showing some settings.
In my AppDelegate, the TabView is added to the window with
[window addSubview:tabBarController.view];
I browsed the web and found this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:tabBarController.view
cache:YES];
[window addSubview:settingsViewController.view];
[UIView commitAnimations];
But when I test this in the simulator the only change I can see is that the TabMenu floats from right to left.
Can this be solved?

You could present the settings view as a modal view. You can specify the animation to flip from right to left.
[settingsViewController.view setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[tabBarController presentModalViewController:settingsViewController animated:YES];
To return:
[self.parentViewController dismissModalViewControllerAnimated:YES];

Thanks, that worked. But I had to insert a navigationController:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
[navigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[tabBarController presentModalViewController:navigationController animated:YES];
[navigationController release];
[settingsViewController release];
But now the next question: How do I get back? :)

Related

Present modalViewController in another view

I've implemented a facebook like slide menu. When I swipe the navigationBar, the "Settings" view will appear underneath.
The problem is when I try to present a modal view from the Settings view. I try to implement a feedback system (MFMailComposeViewController), but if I present it from the Settings view underneath, half of the modal view will be blocked by the overlay view (The rootView controller).
What can I do to fix this problem?
Thanks in advance
masterViewController = [[MatchTable alloc] initWithNibName:#"MatchTable" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
Settings *sideMenuViewController = [[Settings alloc] initWithNibName:#"Settings" bundle:nil];
// make sure to display the navigation controller before calling this
[MFSideMenuManager configureWithNavigationController:self.navigationController sideMenuController:sideMenuViewController];
Well i did it like this to give it a sort of animation effect..You can choose any other effect you like:
[UIView beginAnimations:#"Flip" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:appDelegate.window.rootViewController.view cache:YES];
[appDelegate.window.rootViewController.view addSubview:#"Your View Object"];
[UIView commitAnimations];

iPhone View Animation

I am trying to switch views, but I want the animation with the view lifts up and its like a piece of paper folding to see what is underneath.
Any tutorials or examples of how to get that view animation, if it is an animation, would be appreciated.
Actually the view that the maps app uses when you hit the button on the corner.
Something like this should work:
MyViewController *myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
myView.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissModalViewControllerAnimated:)] autorelease];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:myView];
navigation.modalTransitionStyle = UIModalTransitionStylePartialCurl;
navigation.delegate = self;
[self presentModalViewController:navigation animated:YES];
The key here is the modalTransitionStyle property needs to be set to UIModalTransitionStylePartialCurl before presenting the modal view.
More info here: UIViewController Class Reference (look for modalPresentationStyle, modalTransitionStyle, presentModalViewController:animated:, and dismissModalViewControllerAnimated:).
There are two basic ways of doing this, the old one which is no longer recommended:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:containerView cache:YES];
[containerView addSubview:subview];
[UIView commitAnimations];
And the new one (It uses blocks which are supported from iOS 4 and on):
[UIView transitionWithView:containerView duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [containerView addSubview:subview]; }
completion:nil];

How do I use Flip Transition to go from a UIView to a TableViewController with a NavigationController?

I have two views: one has just a button (view 1) and the other contains a tableview with a search bar (screen2). When the user clicks that button in view 1, I want view 1 to flip and display screen 2.
View 2 resides inside of the navigational controller with a navigation bar on top.
Below is what I have for now. The transition animation works and flips to the second screen but view 2 is missing the SearchBar and title from NavigationBar. Both are set inside view 2.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
navigationController = [[UINavigationController alloc] init];
bestbuyProducts = [[BestBuyProductsViewController alloc] initWithNibName:#"BestBuyProductsViewController" bundle:nil];
[navigationController pushViewController:bestbuyProducts animated:NO];
[navigationController.view setFrame: [self.view bounds]];
[bestbuyProducts release];
[self.view addSubview:navigationController.view];
[UIView commitAnimations];
Thank you
To start your UINavigationController is not initialise correctly. Use the initWithRootViewController: method like that:
bestbuyProducts = [[BestBuyProductsViewController alloc] initWithNibName:#"BestBuyProductsViewController" bundle:nil];
// Initialise the navigation view with the bestbuyProducts view controller
navigationController = [[UINavigationController alloc] initWithRootViewController:bestbuyProducts ];
Then try to use modal view transition to make a flip animation, It's easier and more safe to start:
[navigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[bestbuyProducts release];
OK here is the correct version
navigationController = [[UINavigationController alloc] initWithRootViewController:bestbuyProducts];
[bestbuyProducts setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navigationController animated:YES];

How to add UIview animation transition in MailComposerViewController?

I am using the following code:
- (void)flip
{
MailComposerViewController *mailView = [[MailComposerViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:window
cache:YES];
[mtController.view removeFromSuperview];
//[self.window addSubview:[mailComposer view]];
[self presentModalViewController:mailView animated:YES];
[UIView commitAnimations];
[mailView release]
}
here mtController is a navigation controller (XIB file). I removed it and I add mailview, but the simulator does not show it. What am I doing wrong?
What are you trying to do? Less Vague Questions Is A Good Thing™. Are you trying to use a standard Mail compose controller and use it to flip over instead of present normally?
If so, you can do this:
MailComposerViewController *mailView = [[[MailComposerViewController alloc] init] autorelease];
mailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mailView animated:YES];

How can I change the animation style of a modal UIViewController?

I'm currently displaying a UIViewController like this:
[[self navigationController] presentModalViewController:modalViewController animated:YES];
and hiding it like this:
[self.navigationController dismissModalViewControllerAnimated:YES];
The animation is "slide up from the bottom"... then slide back down. How can I change the animation style? Can I made it fade in/out?
Cheers!
For iPhone 3.0+, a basic crossfade is easiest to do like this:
modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[[self navigationController] presentModalViewController:modalViewController
animated:YES];
Marcus Zarra posted a great solution to this on the SDK mailing list:
UIViewController *controller = [[[MyViewController alloc] init] autorelease];
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[navController presentModalViewController: controller animated: NO];
[UIView commitAnimations];
There are transitions for flipping and page-curling. If you are set on fading, can try adjusting your new view's alpha:
UIViewController *controller = [[[MyViewController alloc] init] autorelease];
controller.view.alpha = 0.0;
[navController presentModalViewController: controller animated: NO];
[UIView beginAnimations: nil context: nil];
controller.view.alpha = 1.0;
[UIView commitAnimations];
However, what you probably want is a crossfade, or at least a fade-over. When the UINavigationController switches to a new view, it removes the old one. For this effect, you're probably better off just adding a new view to your existing UIViewController and fading its alpha in over time.
Note: If you are not in your app delegate [self window] will not work. Use self.view.window , thanks to user412500's post for pointing this out.
To update for alpha fading in iOS 4:
modalController.view.alpha = 0.0;
[self.view.window.rootViewController presentModalViewController:modalController animated:NO];
[UIView animateWithDuration:0.5
animations:^{modalController.view.alpha = 1.0;}];
It should be [self.view.window] in order for the code to work
(at least that's the way that it is in ios 3.2)