views:

2321

answers:

3

I have an app that has a centre view with two views off to each side of it. I want to have two navigation bar buttons, left and right which push a new navigation controller onto the view from the left or the right.

When you change views by pushing a new view using the pushviewController: method of NavigationController, the view appears to slide in from the right. how do i change this to slide in from the left?

+2  A: 

Instead of using a navigation controller, I would just move the view.

CGRect inFrame = [currentView frame];
CGRect outFrame = firstFrame;
outFrame.origin.x -= inFrame.size.width;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];

[newView setFrame:inFrame];
currentView setFrame:outFrame];

[UIView commitAnimations];
Reed Olsen
so load the view controller in the normal manner, then get a handle on the view, then move it? i would also have to manually change the Navigation bar buttons as well
Aran Mulholland
Right. Load the view controller as normal, and move currentView off of the screen and move newView in.
Reed Olsen
this works (you have to replace the -= with a +=) to slide in from the left. however that means manually doing all the buttons back and forward for each view. what a pain.
Aran Mulholland
any idea on how to style the buttons so they are the "pointy" type used in navigation usually? (the back button)
Aran Mulholland
+2  A: 

I don't think you can explicitly define sliding direction in UINavigationControllers. What you might be able to do is pop the current view off the navigation stack to show the prior view, which would animate in the manner you want. However this may be complex if you want to have different view controllers appear depending on what you do on the current view.

If your workflow is not too complicated, you can hold a reference to the prior view controller in the current view controller. depending on what you do on the current view (like select a table view cell), you can change whatever data you need in the prior view controller, and then call

[self.navigationController popViewController];

or whatever the correct method is (i think that's pretty close to how it is). that would let you move down the nav stack with the animation you want, which works if your nav stack has a set number of views on it.

Kevlar
A: 

To get the "pointy" type button you need to use a different method.

In your AppDelegate:

UITableViewController *first = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
UITableViewController *second = [[SomeOtherViewController alloc] initWithStyle:UITableViewStylePlain];

NSArray *stack = [NSArray arrayWithObjects: first, second, nil];

UINavigationController *nav = [[UINavigationController alloc] init];
[nav setViewControllers:stack animated:NO];
carnz