1.自己的方法
- (void)pushVCWithFadeinTransition:(UIViewController *)VC
{
CATransition *transition = [CATransitionanimation];
transition.duration =kFadeinFadeoutAnimatorDuration;
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionFade;
transition.delegate =nil;
[self.view.layeraddAnimation:transition forKey:nil];
/*
//也可以用CAKeyFrameAnimation定义自己的动画实现,自由度更大
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
//缩放倍数
NSArray* arrScales = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DIdentity],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(kAppLaunchScreenScale, kAppLaunchScreenScale, 1.0)], nil];
[animation setValues:arrScales];
[animation setKeyTimes:@[@(0.0),@(1.0)]];
[animation setDuration:kAppLaunchScreenTimeInterval];
[animation setAutoreverses:NO];
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.delegate = self;
animation.beginTime = 0.0;
*/
[selfpushViewController:VC animated:NO];
}
- (UIViewController*)popVCWithFadeoutTransition
{
return [selfpopVCWithFadeoutTransition:kFadeinFadeoutAnimatorDuration];
}
- (UIViewController*)popVCWithFadeoutTransition:(float)timeInterval
{
CATransition *transition = [CATransitionanimation];
transition.duration =timeInterval;
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionFade;
transition.delegate =nil;
[self.view.layeraddAnimation:transition forKey:nil];
return [selfpopViewControllerAnimated:NO];
}
2.网上的方法
#import "UINavigationController+ja.h"
// 扩展NavigationController中的方法(catagory)
@implementation UINavigationController (ja)
- (void)pushAnimationDidStop {
}
- (void)pushViewController: (UIViewController*)controller
animatedWithTransition: (UIViewAnimationTransition)transition {
[self pushViewController:controller animated:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
- (UIViewController*)popViewControllerAnimatedWithTransition:(UIViewAnimationTransition)transition {
UIViewController* poppedController = [self popViewControllerAnimated:NO];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
[UIView setAnimationTransition:transition forView:self.view cache:NO];
[UIView commitAnimations];
return poppedController;
}