我看到很多人询问如何UINavigationController
使用除默认动画之外的其他动画来推送/弹出 s,例如flip
或curl
。
问题是问题/答案相对较旧,这意味着有一些东西[UIView beginAnimations:]
(例如这里)或者他们使用两种非常不同的方法。
第一种是transitionFromView:toView:duration:options:completion:
在推送控制器之前使用 UIView 的选择器(动画标志设置为NO
),如下所示:
UIViewController *ctrl = [[UIViewController alloc] init];
[UIView transitionFromView:self.view
toView:ctrl.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromTop
completion:nil];
[self.navigationController pushViewController:ctrl animated:NO];
另一种是CoreAnimation
显式使用CATransaction
如下:
// remember you will have to have the QuartzCore framework added to your project for this approach and also add <QuartzCore/QuartzCore.h> to the class this code is used
CATransition* transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
transition.duration = 1.0f;
transition.type = @"flip";
transition.subtype = @"fromTop";
[self.navigationController.view.layer removeAllAnimations];
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
UIViewController *ctrl = [[UIViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:NO];
两种方法各有利弊。
第一种方法为我提供了更简洁的代码,但限制了我使用“suckEffect”、“cube”等动画。
第二种方法光看就感觉不对。它首先使用未记录的转换类型(即CATransition Class Reference的Common transition types 文档中不存在),这可能会使您的应用程序被 App Store 拒绝(我的意思是我可能找不到任何应用程序引用被拒绝,因为它正在使用这笔交易,我也希望对此事做出任何澄清),但它为您的动画提供了更大的灵活性,因为我可以使用其他动画类型,例如“cameraIris”、“rippleEffect”等。
QuartzCore
关于这一切,我真的需要上诉吗?CoreAnimation
每当我需要更好的UINavigationController
过渡时?有没有其他方法可以仅使用来达到相同的效果UIKit
?
如果不是,使用“flip”和“cube”之类的字符串值而不是预定义的常量(kCATransitionFade
,kCATransitionMoveIn
等...)是否会成为我在 App Store 中批准应用程序的问题?
此外,这两种方法是否还有其他优点和缺点可以帮助我决定是否选择其中的每一种?