Creating a custom View Controller Animation - ios

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];

Related

Push view controller flip transition doesn't include navigation bar

I am pushing a view controller whilst animating it so it flips. However, the animation is only applied to the view beneath the navigation bar, so the navigation bar hides for a few seconds then suddenly appears again. How can I apply the animation to the entire view, including the navigation bar?
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"OverviewiPad" bundle:nil];
OverviewViewController *overviewVC = [sb instantiateViewControllerWithIdentifier:#"OverviewViewController"];
overviewVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:overviewVC animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

How to set animation to pop the pushed UIViewController

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];

iPhone - Flip animation when navigation controller popped

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.

IOS: custom transition for a viewController

I have this code in my app to do a transition for a viewcontroller
SecondViewController *second = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.view addSubview:second.view];
[second.view setFrame:CGRectMake(320, 0, 320, 480)];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.40]; //the double represents seconds
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[second.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
and it work fine;
but inside second view controller I have this code to disappear this viewcontroller
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.40]; //the double represents seconds
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.view setFrame:CGRectMake(320, 0, 320, 480)];
[UIView commitAnimations];
it work fine, but what's the way to release it, where can I release this second that I alloc when I call it??
if I write [self.view removeFromSuperView]?? is it released??
You need to remove it from the superView then release the SecondViewController that you allocated in your code.
SecondViewController *second = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
So since you are owning this object you need to release it.
So somewhere after hiding the second view, and removing it from superView, you need to release it...
[second release];

how to push a viewController with flip animation

[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.

Resources