ViewContoller animation from top to bottom - ios

I m developing a E-commerce mobile application in iOS. I need to know how to move from one UIViewController to another UIViewController with slide animation from top to bottom.
I am using Storyboard.
App needs to works in ios6 and ios7.
Below is the code i used for tranitioning UIViewController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MenuViewController *viewController =
(MenuViewController *)
[storyboard instantiateViewControllerWithIdentifier:#"menupage"];
[self.navigationController pushViewController:viewController animated:NO];
Below is the code I tried for a turn page effect and it worked fine. I need the same thing as below for a slide top to bottom
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:viewController animated:YES];
[UIView commitAnimations];
The another method
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MenuViewController *viewController = (MenuViewController *)[storyboard instantiateViewControllerWithIdentifier:#"menupage"];
MenuViewController *viewController1 = (MenuViewController *)[storyboard instantiateViewControllerWithIdentifier:#"menupage"];
[self.view addSubview:viewController.view];
viewController.view.frame=CGRectMake(0,480,320,480);
[UIView animateWithDuration:1
animations:^{
viewController.view.frame=CGRectMake(0,0,320,480);
}
completion:^(BOOL fin){
if (fin)
{
[self.navigationController pushViewController:viewController animated:NO];
[self.navigationController pushViewController:viewController1 animated:NO];
}
}];
Here i get animation in success manner.But i need to load same view controller twice.One is for animation and another one is for normal ViewController Load.If i didnt load second method i get some problem in nextviewController button actions.
Thanks in Advance
Sam.P

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.navigationController.view cache:NO];
instead of using UIViewAnimationTransitionCurlUp use UIViewAnimationCoverVertical
or simply without any view animations, just change a single line.
[self.navigationController presentViewController:viewController animated:YES completion:NULL];

FYI #MaheThiru the push only gives u to and fro transition and for push u need navigation controller. the other transitions like coververtical, pagecurl, crossdissolve and fliphorizontal are provided by modal transition(without navigation controller) which we write as
[self presentViewController:viewController animated:YES completion:NULL];
and i got a small doubt here y r u writing
animated:NO
change it to
animated:YES
maybe it will solve the problem. try it once.
Happy coding

Related

Flip transition UINavigationController push does not call viewDidLoad until animation completed

I'm animating UINavigationController push to be a flip following this, but the problem is that viewDidLoad does not get called until the animation is completed, which looks bad since I'm loading photos and such on the destination view controller. How can I ensure that the destination view controller is 'ready to go' (viewDidLoad) called and everything initialized before the animation starts?
[UIView transitionWithView:self.navigationController.view
duration:0.75
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.navigationController pushViewController:viewcontroller animated:NO];
}
completion:nil];
It sounds like your order of events is mixed up. Ideally the photos should get loaded in their own method. You can call this in the "ViewWillAppear" method so it's done before the view is loaded. In your case, if you move the image loading to a method, you can call it just above your [self.navigationController pushViewController:viewcontroller animated:NO]; line.
[viewcontroller loadImageMethod];
[UIView transitionWithView:self.navigationController.view
duration:0.75
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.navigationController pushViewController:viewcontroller animated:NO];
}
completion:nil];

Storyboard Segue Transition Effects

First time poster, long time observer.
I am using storyboards for an app I am working on at present, and require more of a transition than just going forward, for going back in particular. Whenever i use this segue i have for going back through a menu, the next button that is clicked on to go to another ViewController, will crash the whole app!
No idea whats going on, i am using this in the implementation file
#import "SlideLeftSegue.h"
#implementation SlideLeftSegue
- (void)perform{
UIView *sv = ((UIViewController *)self.sourceViewController).view;
UIView *dv = ((UIViewController *)self.destinationViewController).view;
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
dv.center = CGPointMake(sv.center.x - sv.frame.size.width, dv.center.y);
[window insertSubview:dv belowSubview:sv];
[UIView animateWithDuration:0.4
animations:^{
dv.center = CGPointMake(sv.center.x,
dv.center.y);
sv.center = CGPointMake(sv.center.x + sv.frame.size.width,
dv.center.y);
}
completion:^(BOOL finished){
[[self destinationViewController]
dismissViewControllerAnimated:NO completion:nil];
}];
}
#end
This is my header file
#import <UIKit/UIKit.h>
// Move to the previous screen with slide animation.
#interface SlideLeftSegue : UIStoryboardSegue
#end
I am still learning, so if you have any idea whats happening, id appreciate an explanation at a beginner level.
You can achieve that with less code
To present a view controller:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:#"ViewID"];
view.modalTransitionStyle = UIModalTransitionStyleCoverVertical; // you can try the other 3 UIModalTransitionStyle too
[self presentViewController:view animated:YES completion:nil];
To go back:
[self dismissViewControllerAnimated:YES completion:nil];

[self.navigationController pushViewController:ngView animated:YES]; not working

If i use
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self presentViewController:ngView animated:NO completion:nil];
above code the controller will go to NGViewController page.
But if I use this navigation controller
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self.navigationController pushViewController:ngView animated:YES];
the Controller will be in same page.
Can any one tell that what's the problem.
You should use this code
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self presentViewController:ngView animated:NO completion:nil];
after writting this line when then you you want go on different page with push view controller
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:ngView];
[self.navigationController pushViewController:navigationController animated:YES];
I hope you will solve this issue by this code Good luck
Your self.navigationController is probably nil - check it out through debugging. Your self view controller is not within a UINavigationController.
Now i m using this code
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.50];
[self presentViewController:ngView animated:NO completion:nil];
so that it wil give same effect other
Self Controller should have navigation controller (in Storyboard) in order to navigate.
[self.navigationController pushViewController:nextController animated:YES];
UINavigationController is a controller of controllers and it is designed to allow you to push and pop controllers and manage a hierarchy of your view's. And your navigationController property tells you whether your NGViewController is currently in a UINavigationController's hierarchy; if not (as in this case), the navigationController property returns nil.
You have to create your own navigation controller and then try to push the view controllers and thus build up a view hierarchy.
I normally would suggest this:
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:firstviewController];
[self.window setRootViewController:navigationController];
navigationController.delegate = self;
navigationController.navigationBarHidden = YES;
you need to declare this in your first controller
NGViewController *ngView = [[NGViewController alloc]init];
[self.navigationController pushViewController:ngView animated:YES];

Transition between two UIViewControllers with no animation

From my appDelegate I load the the homeScreen ViewController like this:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [sb instantiateViewControllerWithIdentifier:#"HomeScreen"];
[self.window setRootViewController:controller];
The app only ever then changes between my 'homeScreen' and 'PlayViewController' ViewControllers and that is done like this:
PlayViewControlller* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PlayViewController"];
[self presentModalViewController:vc animated:NO];
and this
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [sb instantiateViewControllerWithIdentifier:#"HomeScreen"];
[self presentModalViewController:controller animated:NO];
respectively.
This all works fine. I am able to switch between the viewcontrollers with uibuttons and the above code. However, I'm not sure what causes this, it happens after I've switched between the two viewcontrollers a few times, but the transition starts to get animated and they start twirling when switching.
Ok so I'm trying to narrow down the problem and see what's causing it. I think its the other animation blocks that I'm using in my app. But there's a lot there so don't know exactly what it is.
OK so I found the line of code that was causing this if anyone happens to find themselves in the same situation.
[UIView beginAnimations:#"Move" context:NULL];

Phonegap/iOS - how to push childviewcontroller?

I'm able to implement the concept of childviewcontroller in my PhoneGap project.
Now when I click on any link of my app, that opens in childviewcontroller successfully.
Here is a line that opens the page in clildbrowser
[super.viewController presentModalViewController:childBrowser
animated:YES ];
Now I want to open childBrowser as a pushViewController. Currently it comes from bottom to top but i want this to open from left to right.
Is there any way? Replacing presentModalViewController to pushViewController fails.
presentModalViewController and pushViewController ar every different in concept.
If you just need to change the animation, you might want to do something like this:
childBrowser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//childBrowser.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//childBrowser.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//childBrowser.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[super.viewController presentModalViewController:modalViewController
animated:YES];
or simply use traditional animations (code needs adapting):
UIViewController *controller = [[[MyViewController alloc] init] autorelease];
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[navController presentModalViewController: controller animated: NO];
[UIView commitAnimations];

Resources