iPhone 模态视图动画帮助
我没有做过太多动画,我需要一些帮助。我有一个 tabBarController
作为我的根控制器,我想要另一个 tabBarController
,我想将它作为模态视图控制器,但我有一个问题动画。
目前有四种动画用于 modalViewControllers,即
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
我想要一个不同的动画 - 从右向左滑动。 - 我怎样才能制作这个动画?
对此有什么帮助吗?
编辑:
我将 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.
There are currently four animations for modalViewControllers
, namely
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
I want a different animation - slide from the right to the left. - How can I do this animation?
Any help with this?
Edit:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以手动编写动画代码。以下是一般步骤:
UIViewController
的子类(本质上是一个用来容纳UITabBarController
的无用控制器) - 我通常称之为ShellViewController
。ShellViewController
的init
方法(无论您使用哪个)中,将其屏幕外的frame
设置为右侧,例如[self.view setFrame:CGRectMake(320, 0, 320, 480)];
ShellViewController
中创建两个方法- (void)presentSelf
- (void)dismissSelf
UITabBarController 时,创建
ShellViewController
的实例UITabBarController
实例放置在ShellViewController
实例中[currentView addSubview:shellViewController.view];
UITabBarController
的ShellViewController
这里是动画输入的代码(例如
- (void)presentSelf
code> 方法):这是动画输出的代码(例如
- (void)dismissSelf
方法):请记住,这些动画方法仅执行以下操作: 。它们不会禁用与当前视图或正在动画输入/输出的 ShellViewController 视图/子视图的交互。您需要在动画期间手动禁用用户交互,然后在动画完成后恢复它。有一个
UIView
方法在动画完成时执行选择器:您可以将其放在上面每个动画块中的
[UIView setAnimationDelegate:self]
之后。当然,您需要自己编写enableUserInteraction
方法...以及disableUserInteraction
方法。走这条路虽然很麻烦,但确实有效。一旦您编写了
ShellViewController
,它就成为了一个很好的可重用代码片段。You could write the animation code manually. Here are the general steps:
UIViewController
(essentially a dud controller to house yourUITabBarController
) - I usually call thisShellViewController
.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)];
ShellViewController
- (void)presentSelf
- (void)dismissSelf
ShellViewController
when you want to present yourUITabBarController
UITabBarController
instance inside of theShellViewController
instance[currentView addSubview:shellViewController.view];
ShellViewController
housing yourUITabBarController
Here is the code for animating-in (e.g. the
- (void)presentSelf
method):Here is the code for animating-out (e.g. the
- (void)dismissSelf
method):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: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.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.将根选项卡栏控制器嵌入 UINavigationController 中。如果不允许,请在它们之间插入一个 UIViewController(使:UINavigationController 嵌入 UIViewController,其中添加了 UITabBarController 的视图)。这很糟糕,但它应该(!)能够工作。
Embed your root tab bar controller in a UINavigationController. If it doesn’t let you, stick a UIViewController in between them (making: UINavigationController embeds UIViewController, which has a UITabBarController’s view added to it). It’s nasty-bad, but it ought (!) to work.
模态视图控制器不会滑入,因为这是标准的堆栈动画(推送或弹出)。这让用户感到困惑。如果它是模态的,你真的应该将其从底部向上滑动或进行翻转或其他操作。
为什么模态视图上需要标签栏?通常,模态视图用于数据输入、音频播放等。 标签栏 HIG 指出“一般来说,使用选项卡栏在应用程序级别组织信息”。在模态视图控制器中使用标签栏会打破这一点。当然,您不必完全遵循 HIG 中的每一条准则,但在这种情况下,您确实应该考虑遵循 Apple 的建议。
您能否告诉我们更多有关您的具体用例的信息,以便我们就合适的解决方案提出建议?也许分段控制更合适?
Modal view controllers don't slide in because that's the standard stack animation (pushing or popping). That's confusing to users. If it's modal you really should slide it up from the bottom or do a flip or something.
Why do you need a tab bar on a modal view? Typically modal views are used for things like data entry, audio playback, etc. The tab bar HIG states "in general, use a tab bar to organize information at the application level". Having a tab bar in a modal view controller breaks that. Granted one doesn't have to follow every guideline in the HIG exactly but this is a case where you really should consider following Apple's advice.
Can you tell us more about your specific use case so we can make suggestions on what might be an appropriate solution? Perhaps a segmented control is more appropriate?