iPhone模式视图动画帮助 [英] iPhone Modal View Animation Help
问题描述
我没有做过太多的动画,我需要一些帮助与此有关。我有一个 tabBarController
作为我的根控制器,而我希望有另一个 tabBarController
,我希望把它作为一个模态视图控制器,我有动画的一个问题。
I have not done much animation, and I need some help with this. I have a tabBarController
as my root controller, and I want to have another tabBarController
, and I want to bring it up as a Modal View Controller, and I have a problem with the animation.
目前有四种动画为 modalViewControllers
,即
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
我想要一个不同的动画 - 从左侧向右滑动。 - 我该怎么做动画
任何帮助?
编辑:
我的想法推到tabBarController导航堆栈很烂!苹果公司的这一做法评论:
My idea to push a tabBarController onto the navigation stack sucks! Apple's comment on this approach:
您永远不希望一个标签栏控制器推到导航控制器的导航堆栈。这样将创建一个不寻常的情况,即在
标签栏只会出现,而特定视图控制器是在导航堆栈的顶部。标签栏被设计成永久的,所以这种方法的瞬态会引起混乱给用户。
You never want to push a tab bar controller onto the navigation stack of a navigation controller. Doing so creates an unusual situation whereby the tab bar appears only while a specific view controller is at the top of the navigation stack. Tab bars are designed to be persistent, and so this transient approach can be confusing to users.
我的想法。有人帮我动画模式视图控制器。
I am out of ideas. Someone help me with the animation for modal view controllers.
推荐答案
您可以手动编写动画code。下面是一些常见步骤:
You could write the animation code manually. Here are the general steps:
- 创建
的UIViewController
的一个子类(主要是废的控制器来容纳你的的UITabBarController
) - 我通常称之为ShellViewController
。 - 在
ShellViewController
的的init
办法(你会用哪一个),设置它的架
屏幕之外的权利,例如:[self.view SETFRAME:CGRectMake(320,0,320,480);
- 创建在
ShellViewController
的两种方法-
- (无效)presentSelf
-
- (无效)dismissSelf
- Create a subclass of
UIViewController
(essentially a dud controller to house yourUITabBarController
) - I usually call thisShellViewController
. - In the
ShellViewController
'sinit
method (whichever one you would use), set itsframe
outside of the screen to the right, e.g.[self.view setFrame:CGRectMake(320, 0, 320, 480)];
- Create two methods within
ShellViewController
- (void)presentSelf
- (void)dismissSelf
下面是code的动画式(例如
- (无效)presentSelf
法):Here is the code for animating-in (e.g. the
- (void)presentSelf
method):[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.15]; //the double represents seconds [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; [[self view] setFrame:CGRectMake(0, 0, 320, 480)]; [UIView commitAnimations];
下面是动画时的code(例如
- (无效)dismissSelf
法):Here is the code for animating-out (e.g. the
- (void)dismissSelf
method):[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.15]; [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; [[self view] setFrame:CGRectMake(320, 0, 320, 480)]; [UIView commitAnimations];
请记住,这些动画的方法做的只有的是:动画。他们不与当前视图也不与
ShellViewController
的看法/这是在被动画子视图/禁用进行互动。你需要动画过程中手动禁用用户交互,然后恢复其动画完成后。有执行时动画完成了一个选择器的的UIView
方法:Keep in mind that these animation methods do only that: animate. They don't disable interaction with the current view nor with the
ShellViewController
's view/subviews which are being animated in/out. You'll need to manually disable user interaction during animation and then reinstate it after the animation is finished. There is aUIView
method that performs a selector when animation is finished:[UIView setAnimationDidStopSelector:@selector(enableUserInteraction)];
您可以把
后,这一权利[UIView的setAnimationDelegate:个体经营]
中的每个动画块以上。当然,你需要写在enableUserInteraction
方法自己...和disableUserInteraction
对于这个问题的方法。You can put this right after the
[UIView setAnimationDelegate:self]
in each animation block above. Of course, you would need to write theenableUserInteraction
method yourself... anddisableUserInteraction
method for that matter.这是一件麻烦事走这条路线,但它的作品。一旦你的
ShellViewController
写上去,它使一个很好的可重用的代码片段。It is a hassle to go this route, but it works. Once you get the
ShellViewController
written up, it makes for a nice reusable snippet.这篇关于iPhone模式视图动画帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-