open another view controllers view from right side of the screen
I want to open a viewcontroller from right side of the screen.
That is on doing
[self presentModalViewController:pvc animated:YES];
I want the another viewcontroller's view to appear as if its sliding from the right of the screen instead of appearing as if it is coming from the bottom of the screen :)
How can I achieve that.开发者_如何学Python Please help :)
What you are looking for is a UINavigationController.
In your app delegate you will have a line that looks like this in applicationDidFinishLoading
:
[window addSubview:viewController.view];
Change that line to these:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:navController.view];
Now instead of [self presentModalViewController:pcv animated:YES];
you can do:
[self.navigationController pushViewController:pcv animated:YES];
This is the control which gives the "slide in from the right" animation. Plus allows you to better control a view stack and navigation within an app. Its the best way to control navigation in your app.
ps: that navController will leak now - its just like this in my example so you can see what I'm doing. You'll want to make the navController an iVar in the .h of your app delegate so you can release it in dealloc
. If you release it like it is now then you won't be able to send messages to it.
Look into UINavigationController - Class Reference. This lets you organize a hierarchy that will slide in from the side. Or you can play with the UIView animation blocks. Figure out whats best for your app. If you have several things you will be pushing from the side, like categories, use UINavigationController. If you just have a simple view you want to come in from the side and leave, you'll want to use the UIView animation or other animation methods. The UIView animation will look like this:
[UIView beginAnimations:nil context:nil];
//code to move view on to screen
[UIView setAnimationDuration:0.5];
[UIView commitAnimations];
精彩评论