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.
Related
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.
I want to slide a UITableVIew into a view (NOT by pushing the view on top of Navigation Controller) on click of a button and then hide it back by sliding , on clicking of the same button.
I want the tableView to slide inside a present view.
You animate the frame property of the table view to move it off screen or back onto screen.
Here is some sample code that moves a table view off screen and moves another on screen in its place:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kSlideTableDuration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(tableAnimationDidStop:finished:context:)];
self.tableView1.frame = offScreen;
self.tableView2.frame = onScreen;
[UIView commitAnimations];
You can read about animation blocks like this in the UIView documentation.
Check out the documentation of UINavigationController. To implement you would do something similar to this:
iPhoneCustomViewController *newView = [[iPhoneCustomViewController alloc] initWithNibName:#"iPhoneCustomViewController" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];
[newView release];
Then, when your done with the CustomViewController do:
[self.navigationController popViewControllerAnimated:YES];
You get the nice slide animations for free if you use a UINavigationController. It will take care of sliding views in (push them on the navigation controller stack) and sliding them out (pop them off the navigation controller stack).
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.