I am trying to push a viewController and I want to change the animation of the push. The original puch animation is flip from right/left, I need to make it from bottom, just like the animation of present.
I tried the following code, it works, but the background will be black when the viewcontroller is animating. What can I do with it?
CATransition *animation = [CATransition animation];
animation.duration = 2.0f;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fillMode = kCAFillModeForwards;
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
[[self.navigationController.view layer] addAnimation:animation forKey:#"animation"];
[self.navigationController pushViewController:controller animated:NO];
Hey you can use below method while pushing a controller in navigation controller with animated NO
- (void)animateControllerFromBottomToTop
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
[animation setDuration:0.65f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.navigationController.view layer] addAnimation:animation forKey:#"AnimationFromBottomToTop"];
}
You can use PRESENT and still have the Navigation Bar.
Let's say your base viewController is VC1 and the next view controller which you need to push is VC2.
Just embed the VC2 inside another Navigation Controller, then create a Present Segue from VC1 to the Navigation Controller heaving VC2 as its Root.
It will be presented with your required animation and will still have the navigation bar.
Hope it helps.
Related
I need Present modal view controller animate from left to right like
drawer?
My code:-
MenuViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"MenuViewStory"];
vc.delegate= self;
CATransition *transition = [CATransition animation];
transition.duration = 0.6;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromLeft;
[vc.view.window.layer addAnimation:transition forKey:nil];
[self presentViewController:vc animated:YES completion:nil];
Hey you can use below method while pushing a controller in navigation controller with animated NO
- (void)animateControllerFromLeftToRight
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.65f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.navigationController.view layer] addAnimation:animation forKey:#"AnimationFromLeftToRight"];
}
I have a problem with custom transition between controllers. I have two view controllers. First is a table view controller and initiate controller is the second one. It has a button on it's top left corner which, when it is pressed, first navigation controller is called. There should be slide animation, but from left to right, not from right to left. I made my own transition but when the button is pressed, transition looks very awful. Transition code:
CATransition *transition = [CATransition animation];
transition.duration = 0.45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionFromLeft;
[transition setType:kCATransitionPush];
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:controller animated:NO];
This is a screenshot, how the transition looks like:
I am using the old (pre-iOS7) push/pop animation by using the method described here:
#implementation UINavigationController (Retro)
- (void)pushViewControllerRetro:(UIViewController *)viewController {
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.layer addAnimation:transition forKey:nil];
[self pushViewController:viewController animated:NO];
}
- (void)popViewControllerRetro {
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:transition forKey:nil];
[self popViewControllerAnimated:NO];
}
#end
My problem is that iOS7 seems to fade the UINavigationBar of the previous view controller when pushing a new view controller. Normally this looks fine because iOS 7 is dragging the views on top of each other. But when I am using the pre-iOS7 animation it gives me a short flash, because the navigation bar fades while the new view it getting pushed in from the right side.
Is there a way to disable the fade animation on the navigation bar?
I'm just a new man to IOS. Here is the storyboard of my app:
I made an animated file *gif and I want to add it between ViewController 1 and ViewController 2. This is how it goes:
when I hit on the button on VC1, animated screen will be showed up (like a loading screen), and the view 2 will be showed up afterward.
How can I do it?
use this this seems close to your problem
CATransition *animation = [CATransition animation];
[animation setDuration:2];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; ECAddToFavoriteViewController *addTofav = [[ECAddToFavoriteViewController alloc]initWithNibName:#"ECAddToFavoriteViewController" bundle:nil];
[self.navigationController pushViewController:addTofav animated:YES];
[[self.view layer] addAnimation:animation forKey:#"SwitchToView1"];
I Try to imitate the NavigationViewController, very similar to default MailApp in iPhone
When clicking on a Mail summary, it should slide-in the mail details, and when BACK button is clicked, Mail Summary view is to be slided-in back again.
This is what I have to animate the transition from Summary To Detail (removeFromSuperView)
CGRect temp = self.view.frame;
temp.origin.x = 300;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
self.view.frame = temp;
}completion:^(BOOL finished){
[self.view removeFromSuperview];
}];
This is what I have to animate the transition from Detail To Summary (addSubview)
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionFromRight;
transition.subtype = kCATransitionFade;
[parentView.layer addAnimation:transition forKey:nil];
[parentView addSubview:myVC.view];
Now, that My First part of code is working well! Where-as the second part, I am just able to achieve the Fade-in animation. How can I bring in the slide transition?
I just need to choose kCATransitionPush type for my CATransition
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[parentView.layer addAnimation:transition forKey:nil];
[parentView addSubview:myVC.view];
Update for Swift:
let transition = CATransition()
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
parentView.layer.add(transition, forKey: nil)
parentView.addSubview(myVC.view)
Or you could check out : HorizontalSlide Segue (just google it I cant get the link, on mobile) its a great sliding transition that is simply a segue that you add from view A to B....
On a side note, if this is in a nav controller, a push or a pop should have a slide animation by default...