简体   繁体   English

iPhone 模态视图 Animation 帮助

[英]iPhone Modal View Animation Help

I have not done much animation, and I need some help with this.我没有做太多 animation,我需要一些帮助。 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.我有一个tabBarController作为我的根 controller,我想要另一个tabBarController ,我想把它作为模态视图 Controller 提出来,我对 Z6F1C25ED15230962F1BBF9DEEBEBE9Z 有问题。

There are currently four animations for modalViewControllers , namely modalViewControllers目前有四种动画,分别是

typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;

I want a different animation - slide from the right to the left.我想要一个不同的 animation - 从右向左滑动。 - How can I do this animation? -我该怎么做 animation?

Any help with this?有什么帮助吗?


Edit:编辑:

My idea to push a tabBarController onto the navigation stack sucks: Apple's comment on this approach:我将 tabBarController 推送到导航堆栈的想法很糟糕:Apple 对这种方法的评论:

You never want to push a tab bar controller onto the navigation stack of a navigation controller.您永远不想将标签栏 controller 推送到导航 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.这样做会产生一种不寻常的情况,即标签栏仅在特定视图 controller 位于导航堆栈顶部时出现。 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.有人帮我使用 animation 用于模态视图控制器。

You could write the animation code manually.您可以手动编写 animation 代码。 Here are the general steps:以下是一般步骤:

  • Create a subclass of UIViewController (essentially a dud controller to house your UITabBarController ) - I usually call this ShellViewController .创建UIViewController的子类(本质上是一个愚蠢的 controller 来容纳您的UITabBarController ) - 我通常称之为ShellViewController
  • In the ShellViewController 's init method (whichever one you would use), set its frame outside of the screen to the right, eg [self.view setFrame:CGRectMake(320, 0, 320, 480)];ShellViewControllerinit方法(无论您使用哪个)中,将其在屏幕外的frame设置为右侧,例如[self.view setFrame:CGRectMake(320, 0, 320, 480)];
  • Create two methods within ShellViewControllerShellViewController中创建两个方法
    • - (void)presentSelf
    • - (void)dismissSelf
  • Create an instance of ShellViewController when you want to present your UITabBarController当你想展示你的UITabBarController时,创建一个ShellViewController的实例
  • Place your UITabBarController instance inside of the ShellViewController instance将您的UITabBarController实例放在ShellViewController实例中
  • Call [currentView addSubview:shellViewController.view];调用[currentView addSubview:shellViewController.view];
  • Use the custom methods above to present and dismiss the ShellViewController housing your UITabBarController使用上面的自定义方法来显示和关闭包含您的UITabBarControllerShellViewController
  • Deal with memory management as your business logic dictates按照您的业务逻辑要求处理 memory 管理

Here is the code for animating-in (eg the - (void)presentSelf method):这是动画输入的代码(例如- (void)presentSelf方法):

[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];

Here is the code for animating-out (eg the - (void)dismissSelf method):这是动画输出的代码(例如- (void)dismissSelf方法):

[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];

Keep in mind that these animation methods do only that: animate.请记住,这些 animation 方法只能做到这一点:动画。 They don't disable interaction with the current view nor with the ShellViewController 's view/subviews which are being animated in/out.它们不会禁用与当前视图的交互,也不会禁用与正在输入/输出动画的ShellViewController的视图/子视图的交互。 You'll need to manually disable user interaction during animation and then reinstate it after the animation is finished.您需要在 animation 期间手动禁用用户交互,然后在 animation 完成后恢复它。 There is a UIView method that performs a selector when animation is finished:有一个UIView方法在 animation 完成时执行选择器:

[UIView setAnimationDidStopSelector:@selector(enableUserInteraction)];

You can put this right after the [UIView setAnimationDelegate:self] in each animation block above.您可以将其放在上面每个 animation 块中的[UIView setAnimationDelegate:self]之后。 Of course, you would need to write the enableUserInteraction method yourself... and disableUserInteraction method for that matter.当然,您需要自己编写enableUserInteraction方法……并为此编写disableUserInteraction方法。

It is a hassle to go this route, but it works. go 这条路线很麻烦,但它有效。 Once you get the ShellViewController written up, it makes for a nice reusable snippet.一旦你编写了ShellViewController ,它就构成了一个很好的可重用代码段。

Embed your root tab bar controller in a UINavigationController.将根标签栏 controller 嵌入到 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).如果它不允许您,请在它们之间粘贴一个 UIViewController(制作:UINavigationController 嵌入 UIViewController,其中添加了一个 UITabBarController 的视图)。 It's nasty-bad, but it ought (.) to work.这很糟糕,但它应该(。)工作。

Modal view controllers don't slide in because that's the standard stack animation (pushing or popping).模态视图控制器不会滑入,因为这是标准堆栈 animation(推送或弹出)。 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".通常,模态视图用于数据输入、音频播放等。 标签栏 HIG声明“通常,使用标签栏在应用程序级别组织信息”。 Having a tab bar in a modal view controller breaks that.在模态视图 controller 中有一个标签栏打破了这一点。 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.诚然,不必完全遵循 HIG 中的每条准则,但在这种情况下,您确实应该考虑遵循 Apple 的建议。

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?也许分段控件更合适?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM