I have a litle problem. I have a pushviewcontroller and it uses an animation.
My code is like this:
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:dtv animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];`
It works good, but when the view is pushed and I go back, this doesn't do the animation.
So I don't know how to do the same animation when I go back.
can anyone help me? Thanks!
As an alternate, you can use this also,
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
//transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[[self navigationController] popViewControllerAnimated:NO];
This is how I've always managed to complete this task.
For Push:
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:dtv animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];`
For Pop:
[
UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
I still get a lot of feedback from this so I'm going to go ahead and update it to use animation blocks which is the Apple recommended way to do animations anyway.
For Push:
MainView *nextView = [[MainView alloc] init];
[UIView animateWithDuration:0.75
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[super pushViewController:nextView animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
}];
For Pop:
[UIView animateWithDuration:0.75
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transition forView:self.navigationController.view cache:NO];
}];
[self.navigationController popViewControllerAnimated:NO];
Related
I want to create transition between view controllers like this.
https://www.dropbox.com/s/qatwqaq2mowocsg/Transitions%20Controller.gif?dl=0
I 've used the following code to create transition but cannot achieve following results.
self.settings = [self.storyboard instantiateViewControllerWithIdentifier:#"settings"];
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.type = kCATransitionPush;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.subtype=kCATransitionFromRight;
[[self navigationController].view.layer addAnimation:transition forKey:kCATransition];
[[self navigationController] pushViewController:self.settings animated:NO];
You can try this code :
self.settings = [self.storyboard instantiateViewControllerWithIdentifier:#"settings"];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:self.settings animated:YES];
[UIView commitAnimations];
Start from iOS7 you can custom the transition effect of system method pushViewController and presentViewController. For example if you need to custom the push effect there is a method in UINavigationControllerDelegate named
- (id<UIViewControllerAnimatedTransitioning> _Nullable)navigationController:(UINavigationController * _Nonnull)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController * _Nonnull)fromVC toViewController:(UIViewController * _Nonnull)toVC
add the custom animation to fromVC's view and show the toVC's view in proper time
While it's not a direct implementable chunk of code that represents THE ANSWER, this blog should get you through the steps to create your own custom transitions: http://blog.dadabeatnik.com/2013/10/13/custom-segues/
I need to present view controller with UIViewAnimationOptionCurveEaseIn animation where source controller disappear from 1 alpha to 0 and destination controller appear from 0 alpha to 1
I'd like to use
presentViewController: animated: completion:
I've tried:
In source controller
UIStoryboard *st = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:#"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
PopViewController *pop = [st instantiateViewControllerWithIdentifier:name];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pop];
nav.navigationBarHidden = YES;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.view.alpha = 0.f;
} completion:^(BOOL finished) {
[self presentViewController:nav animated:NO completion:nil];
}];
In destination controller
- (void)viewDidLoad{
[super viewDidLoad];
self.view.alpha = 0.f;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.view.alpha = 1.f;
} completion:^(BOOL finished) {
}];
but controllers disappear and appear not at the same time
Pavel, for example
-(void)goToViewControllerAction
{
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
CATransition *transition = [CATransition animation];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
transition.duration = 1.5;
[transition setType:kCATransitionFade];
[self.navigationController.view.layer addAnimation:transition forKey:#"someAnimation"];
[self performSegueWithIdentifier:#"backPopsegue" sender:nil];// Here your push or performSegue transition
[CATransaction commit];
}
Don't remember to use QuartzCore)
You can customize your transition like you want, there are a lot of different settings in it....
I am trying to create a view controller animation where the view controller the user is currently on slide down and of the screen, revealing the new view controller bellow. So the new view controller would act like a background, with the new one sliding down and revealing it. I have given it a shot but haven't had any success. How would you recommend doing this?
Here is what I have tried:
-(void)showLogout:(UIButton *)sender {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"TermsAccepted"];
WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
self.view.frame = CGRectMake(0, 1200, 320, 568);
[self.navigationController pushViewController:welcomeViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView commitAnimations];
}
try this
-(void)showLogout:(UIButton *)sender {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"TermsAccepted"];
WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController cache:YES];
self.view.frame = CGRectMake(0, 1200, 320, 568);
[self.navigationController pushViewController:welcomeViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView commitAnimations];
How to Flip animation when navigation is controller popped, how we can achieve this
Following code for the flip animation for pop view
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
Following code for the Animation Block
[UIView animateWithDuration:0.75
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transition forView:self.navigationController.view cache:NO];
}];
[self.navigationController popViewControllerAnimated:NO];
Try This Below Code to Push your View to next view.
-(IBAction)gotonextView:(id)sender
{
NextView *info = [[NextView alloc]initWithNibName:#"NextView" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:info];
info.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:nvc animated:YES];
}
Automatically You will get the same flip animation while popping out.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
alarmViewController = [[AlarmViewController alloc] init];
[self.navigationController pushViewController:alarmViewController animated:YES];
[alarmViewController release];
[UIView commitAnimations];
I just want the viewcontroller flip like opening a book page,but it does not work like this.And I have a question that whether navigationController can animate this effect?
Since you are already putting the navigationController in an animation block. Mark animated:NO -
[self.navigationController pushViewController:alarmViewController animated:NO];
when we actually call pushViewController: we are setting the animated value to NO. This disables the Navigation Controller's default animation. Instead, the block of code uses the defined transition.