I'm trying to replace the window rootViewController with animation and it only works partially.
I create a UINavigationController programatically -
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"InboxStoryboard" bundle:nil];
UIViewController *innerViewController = [storyBoard instantiateViewControllerWithIdentifier:#"centerView"];
UINavigationController *centerView = [[UINavigationController alloc] initWithRootViewController:innerViewController];
Afterwards I replace the window root view controller wrapped in an animation block -
[UIView transitionWithView:self.viewController.view.window
duration:0.5
options: UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
self.viewController.view.window.rootViewController = centerView;
}
completion:nil];
What happens is that the animation happen but the controller that I create is only partially visible, take a look at the following picture -
So as you can see during the rotation the view is only partially rendered.
Anyone bumped into this kind of behaviour before?
So after a long search I found the problem was in the [UIView transitionWithView:...]
Searching a bit more in stackoverflow I found Swapping rootViewController with animation
Using [UIView transitionFromView:..] works perfectly.
The new code -
[UIView transitionFromView:self.window.rootViewController.view
toView:self.centerViewController.view
duration:0.5
options:UIViewAnimationOptionTransitionCurlUp
completion:^(BOOL finished)
{
self.window.rootViewController = self.centerViewController;
}];
Are you using Auto layout? If so, try disabling it. I have run into multiple problems with auto layout and animations.
Related
How can I modify the animation for dismiss?
for present, I've used :
SlideShow *slider = [[SlideShow alloc] initWithNibName:#"SlideShow" bundle:nil];
slider.view.alpha = 0.0;
[self presentModalViewController: slider animated: NO];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
slider.view.alpha = 1.0;
[UIView commitAnimations];
and it works..
But how about a way to dismiss it using a custom animation (I was looking for a Fade-Out animation for dismiss)
Thanks.
You are fading view controllers the old school way, since iOS 3 the easiest and best way to fade a view controller is to set its property: (ex. in the init method)
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
Your view controller will then fade nicely in and out.
presentModalViewController is essentially a method that serves up a pre-baked animation for your viewController.view. If you want to make a custom animation for dismissing or presenting a modal view, you have to handle it all on your own.
I am having a view called NView on which I am having a design button clicking on which I want another view DView in flipview, but it's not working. Below is my code. I got an error called accessing unknown getter method:
NSLog(#"yuppii");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:([NView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView: DView cache:YES];
It's probably because you aren't using a container view as the transition view. Refer to the documentation on setAnimationTransition:forView:cache:
If you want to change the appearance of a view during a transition—for example, flip from one view to another—then use a container view, an instance of UIView, as follows:
1. Begin an animation block.
2. Set the transition on the container view.
3. Remove the subview from the container view.
4. Add the new subview to the container view.
5. Commit the animation block.
Try using self.view.superview in the animation transition view of the showMoreInfo:
The reason the showLessInfo: method works is you are using a container view.
or use this way-may be helped u......
CustomViewController *vc = [[CustomViewController alloc]
initWithNibName:#"CustomViewController" bundle:nil];
vc.delegate = self;
// The magic statement. This will flip from right to left.
// present the modal view controller then when you dismissModalViewController
// it will transition flip from left to right. Simple and elegant.
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:vc animated:YES];
[vc release];
I am flipping over to an info view on the backside. I have it flipping, and I have a navigation bar on the other side to get me back home to the original view (which was a problem when I was trying to use a modal).
My problem now is that it only works the first time: I tap the info button, I flip to the backside. I tap the back button and I can flip back no problem.
But, if I tap that info button again, it pushes over to the info view instead of flipping. The flip back is still fine. If I leave the root view and go elsewhere and come back, it flips properly again.
In the method that is invoked when I click the info button:
InfoViewController *controller = [[[InfoViewController alloc] init] autorelease];
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController pushViewController: controller animated:NO];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Thanks for your help!
where you initializing InfoViewController ?
as every time you come on the Root it's getting initialize and working fine...
When you click back it doesn't.... so easy fix will be write this code in viewWillAppear...which gets called every time you visit the view..
Hope this helps..
Here is a bit newer implementation which uses blocks from newer UIView APIs and relies on ARC.
This is how you push new flipping screen:
InfoViewController *controller = [[InfoViewController alloc] init];
[self.navigationController pushViewController:controller animated:NO];
[UIView transitionFromView:self.view
toView:controller.view
duration:0.8f
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
// Add completion stuff here
}];
And here is the snippet for dismissing it:
[self.navigationController popViewControllerAnimated:NO];
[UIView transitionFromView:controller.view
toView:self.view duration:0.8f
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
// Add completion stuff here
}];
I have a small problem with UINavigationController animation between two view.
My application build more than two view,
first view contains login information, second view contains root menu, last view contains sample data and so on..
My MainWindow.xib contains a UINavigationController component which is contains all navigation structure.
When my login view loaded, i use this lines of code
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
for hide UINavugationConttoller (I don't need to show to user navigation bar during the login.)
After that when the user execute the login submit button on the login view
i use this code for push the RootmenuView to the UINavigationController's stack.
RootMenuController *rootMenuController = [[RootMenuController alloc] initWithNibName:#"RootMenuController" bundle:0];
[self.navigationController pushViewController:rootMenuController animated:NO];
[rootMenuController release];
It's working very well. And when the Rootmenuview loaded user have to show the navigation bar then i'm showing the UINavigation's tool bar with this code
- (void)viewDidAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
But i don't like the default animation transitions of UINavigationController then i changed above code with below
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.50];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:YES];
RootMenuController *rootMenuController = [[RootMenuController alloc] initWithNibName:#"RootMenuController" bundle:0];
[self.navigationController pushViewController:rootMenuController animated:NO];
[UIView commitAnimations];
[rootMenuController release];
It's working too but UINavigationController flickering during between two view naimation transition.
I didn't solve this problem.
Any suggestions ?
Thank you
Have you tried [setAnimationTransition:forView:cache:NO]? I got some odd behavior similar to yours when I used to mess around with UIView animations and used caching.
i have coded following in appDelegeate .m file .but i cant run presentModalViewController method.if i run [self.window addSubview:mview] ,it does not show the result..?any help
to go from one controller to another controller?here mtController is Navigationcontroller.
- (void)flip
{
MViewController *mview = [[MViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:window
cache:YES];
[mtController.view removeFromSuperview];
[self.window addSubview:mview];
// [self presentModalViewController:mailView animated:YES];
[UIView commitAnimations];
[mailView release]
}
If you want to add a NavigationController to a window you are supposed to call
[self.window addSubview:mview.view];
And if you want to go from one view in a NavigationController to another view, the correct thing to do would be to push the new ViewController.
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
In your code sample you create an object called mview, but then below in the presentModalViewController you reference mailView (and in the release). Is that a mistake?
After you add the mview.view to the window, is it the only view on the stack? If not, you might need to bring it to the front. Also, assuming the release statement at the bottom was meant to be [mview release] you're going to have another problem if you don't save/retain that view controller. I don't believe adding it to the window subviews retains it.