我看到很多人问如何推动/流行UINavigationController
s使用其他动画,除了默认的,如flip
或curl
。什么是正确的方法来改变UINavigationController转换效果
问题是,问题/答案是相对较旧的,这意味着有一些东西,如[UIView beginAnimations:]
(示例here),或者他们使用两种截然不同的方法。
首先是按下控制器(设置为NO
动画标志)之前使用的UIView的transitionFromView:toView:duration:options:completion:
选择器,如下所示:
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”和others。
第二种方法只是看着它而感觉不对。它通过使用未公开的转换类型(即不存在于Common transition types documentation中的CATransition Class Reference)开始,这可能会让您的应用程序在App Store中被拒绝(我的意思是可能无法找到任何应用程序被拒绝的参考,因为它使用的是这些事务,也会对这件事情有所澄清),但它给了你更多的动画灵活性,因为我可以使用其他动画类型,例如“cameraIris”,“rippleEffect”等等。
关于这一切,我是否真的需要上传QuartzCore
和CoreAnimation
,无论何时我需要一位鸽友UINavigationController
转换?有没有其他方法可以仅使用UIKit
来实现相同的效果?
如果不是,那么使用像“flip”和“cube”这样的字符串值而不是预定义的常量(kCATransitionFade
,kCATransitionMoveIn
等等)是否会成为我App在App Store中批准的问题?
此外,是否有其他利弊两种方法,可以帮助我决定是否选择其中每一个?
前段时间我曾尝试过cocos2d,在1之前waaay。0发布,并且据我记得我不能将他们的动画与UIKit一起使用,我的意思是,我必须使用他们的CCxxx类,如CCSprites或类似的东西......所以可以使用他们的动画框架,同时推动' UIViewController'在我的'UINavigationController'中?那将是真棒!如果是的话,你能提供一些如何完成这些的代码? – 2012-04-11 21:34:20
我不认为这是可能的,Cocos2D使用OpenGL并管理它自己的视图等。 – 2012-11-28 15:27:52