3

我看到很多人询问如何UINavigationController使用除默认动画之外的其他动画来推送/弹出 s,例如flipcurl

问题是问题/答案相对较旧,这意味着有一些东西[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 中批准应用程序的问题?

此外,这两种方法是否还有其他优点和缺点可以帮助我决定是否选择其中的每一种?

4

1 回答 1

1

关于 AppStore 的批准,根据您使用的动画库,我认为它不会破坏交易。你可以使用任何你觉得方便的,也可以一起使用。从个人的角度来看,当您尝试将动画添加到特定事件时,我会说CoreAnimation&QuartzCore非常棒。它很棒,因为您可以添加到各个组件的详细程度。

但这些不是你唯一的选择。你应该看看COCOS2D动画库。它们真的很棒,而且使用起来非常简单。例如,如果 usingCoreAnimation需要 30 行代码,您可以使用COCOS2D3-5 行代码来设置它。此外,您可以在使用COCOS2D框架 ( chipmunk) 时将 Physics 与每个组件集成。

于 2012-04-11T20:18:37.073 回答