Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Pushing View Controller in a left direction

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?

like image 544
Aran Mulholland Avatar asked Jul 08 '09 04:07

Aran Mulholland


3 Answers

I have done change animation direction when we push viewcontroller. you can change animation type here [animation setSubtype:kCATransitionFromRight];

 ViewController *elementController = [[ViewController alloc] init];

// set the element for the controller
ViewController.element = element;


// push the element view controller onto the navigation stack to display it

CATransition *animation = [CATransition animation];
[[self navigationController] pushViewController:elementController animated:NO];
[animation setDuration:0.45];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[elementController.view layer] addAnimation:animation forKey:@"SwitchToView1"];

[elementController release];
like image 136
milanjansari Avatar answered Oct 13 '22 19:10

milanjansari


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];
like image 8
Reed Olsen Avatar answered Oct 13 '22 18:10

Reed Olsen


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.

like image 4
Kevlar Avatar answered Oct 13 '22 17:10

Kevlar