我在我的iOS应用程序中使用自定义动画进行导航.
我有一个UINavigationController的子类,其中重写了以下方法:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { CATransition* transition = [CATransition animation]; transition.duration = 0.4; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]; transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //,kCATransitionPush,kCATransitionReveal,kCATransitionFade transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft,kCATransitionFromRight,kCATransitionFromTop,kCATransitionFromBottom [self.view.layer addAnimation:transition forKey:@"Push"]; [super pushViewController:viewController animated:NO]; } - (UIViewController *)popViewControllerAnimated:(BOOL)animated { CATransition* transition = [CATransition animation]; transition.duration = 0.4; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]; transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //,kCATransitionFade transition.subtype = kCATransitionFromRight; //kCATransitionFromLeft,kCATransitionFromBottom [self.view.layer addAnimation:transition forKey:@"Pop"]; UIViewController *poppedVC = [super popViewControllerAnimated:NO]; return poppedVC; }
我不记得链接,但我从这里的一个问题复制了这个代码,一点点修改对我有用.
现在,当我将代码移植到iOS 7 SDK时,导航时会显示黑色背景.
我在这里发布了一个视频:Black background while navigation in iOS app,以便说清楚.
注意:我的应用程序中的要求是当推/弹时动画与默认的左右和左右相反.当我针对iOS 5并且没有显示黑色背景/屏幕时,此代码工作正常.