2

I am having four ViewControllers , where the ViewControllers are loaded using the UINavigationController. I am able to switch to every ViewController one by one.

The thing is, since I am using the NavigationController all the ViewControllers are loaded either from the Left or from the Right. But I want to load the ViewController from the Bottom. I know I can use presentModalViewController to present the ViewController from the Bottom. But it is not equivalent to the Navigation Controller because , from the 4th ViewController, If I press one button , I need to come to the 1st ViewController.

How can I present a ViewController from the bottom in the NavigationController ?

Cyril
  • 1,216
  • 3
  • 19
  • 40
Perseus
  • 1,546
  • 4
  • 30
  • 55
  • 2
    You can use custom animation using block statement :) – The iOSDev Aug 09 '12 at 08:53
  • Custom Animation for Navigation Controller ? – Perseus Aug 09 '12 at 09:00
  • @AalokParikh. Actually , I was using 4 ViewControllers without Navigation. But in one case , I want to jump from 4th to 1st ViewController, so I used the NavigationController,But after using the Navigation,the ViewController are being pushed from the Left or Right side. – Perseus Aug 09 '12 at 09:03
  • Yes just pass NO to animated: parameter and then you can use custom animation – The iOSDev Aug 09 '12 at 09:04
  • It's just fine I have used same type of hierarchy in my one project :) – The iOSDev Aug 09 '12 at 09:05
  • @AalokParikh. Have you seen the iPhone Developer answer, I am trying to do in that way, But I don't have options to present the viewcontroller from the Bottom. Any help ? – Perseus Aug 09 '12 at 09:23
  • Ok then use custom frame setting initially place it to the bottom of screen and then finally put it to the exact location you want. Practically for hidden frame's x,y will be 0,480 (iPhone with statusbar hidden) and for fully visible it will be 0,0 :) – The iOSDev Aug 09 '12 at 09:42
  • Try my answer :) Replace the custom variables with hard coded values as I said in above comment :)\ – The iOSDev Aug 09 '12 at 09:45

3 Answers3

10

Try this:

CATransition *animation = [CATransition animation]; 
[animation setDuration:2]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromTop]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
SecondView *sObj=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:sObj animated:YES];
[[sObj.view layer] addAnimation:animation forKey:@"SwitchToView1"]; 
Morteza Soleimani
  • 2,652
  • 3
  • 25
  • 44
Tripti Kumar
  • 1,559
  • 14
  • 28
  • I tried many types, I cant find any animationTransition which will present from the bottom ? – Perseus Aug 09 '12 at 09:24
  • Then use this: CATransition *animation = [CATransition animation]; [animation setDuration:2]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromBottom]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [[self.view layer] addAnimation:animation forKey:@"SwitchToView1"]; – Tripti Kumar Aug 09 '12 at 09:36
  • I tried using the following code, but it loads the ViewController immediately. without animation – Perseus Aug 09 '12 at 09:44
  • CATransition *animation = [CATransition animation]; [animation setDuration:5]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromTop]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [[self.view layer] addAnimation:animation forKey:@"SwitchToView1"]; [self.navigationController setNavigationBarHidden:NO]; [self.navigationController pushViewController:_secondViewController animated:NO]; – Perseus Aug 09 '12 at 09:45
  • Yep. Its working fine. But first time it looks ok.Thank you. But I wonder how to remove it in the same way. I mean from the Top. – Perseus Aug 09 '12 at 10:09
  • You can use the same code, except use "kCATransitionFromBottom" instead of "kCATransitionFromTop" and add the animation on firstViewController – Tripti Kumar Aug 09 '12 at 10:31
0

Use this may this will help you

[UIView beginAnimations:@"Hide Me" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:kAnimationDur];
subScroll.frame = CGRectMake(0,ksubScrollHideY,ksubScrollW,ksubScrollH);
clickPic.frame = CGRectMake(kButtonX,kButtonHiddenY,kButtonW,kButtonH);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

Happy Coding :)

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
-2

after you create the viewController, instead of:

[self.navigationController pushViewController:blablabla animated:YES];

do:

[self presentModalViewController:blablabla animated:YES];

and it will come from the bottom.

to go back, just say:

[self dismissViewControllerAnimated:YES];
John Smith
  • 2,012
  • 1
  • 21
  • 33
  • Yes. I know about this and I have used this. But I want to push the ViewController from the Bottom for the Navigation Controller. In your case, If I am in 4th ViewController, I press one button how to come back to the 1st ViewController which is a root view controller – Perseus Aug 09 '12 at 08:49
  • Aaa, my friend, I guess you will have to first:dismiss the modally presented controller, then, in your previous controller, in viewDidAppear, check if you came from modal, and if yes, pop to root controller, or anywhere else back. – John Smith Aug 09 '12 at 08:51
  • another way: you dismiss the modal with animated:NO, then in previous controller in viewWillAppear (not didAppear), jump to the needed navigationController. this way you will not see the previous controller. but of course, in viewWillAppear, you will have to check if you came from modal – John Smith Aug 09 '12 at 08:53