UINavigationController和autorotation [英] UINavigationController and autorotation

查看:135
本文介绍了UINavigationController和autorotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIViewController,在中返回 YES UIDeviceOrientationPortrait 其他一切都是c $ c>和。使用堆栈顶部的视图,我使用 pushViewController:animated:来推送一个新的 UIViewController 。对于 shouldAutorotateToInterfaceOrientation:中的任何内容,新控制器返回 YES

I have a UIViewController that returns YES in shouldAutorotateToInterfaceOrientation: for UIDeviceOrientationPortrait and NO for everything else. With that view on the top of the stack, I use pushViewController:animated: to push a new UIViewController. The new controller returns YES for anything in shouldAutorotateToInterfaceOrientation:.

第一个视图拒绝旋转(如预期的那样)。按下第二个视图后,用户可以旋转设备,UI将旋转(也如预期)。如果第二个视图处于横向模式并且用户按下后退按钮(调用 popViewControllerAnimated:),则第一个视图将显示为旋转(意外!)。

The first view refuses to rotate (as expected). Once the second view is pushed, the user can rotate the device and the UI will rotate (also as expected). If the second view is in landscape mode and the user presses the back button (which calls popViewControllerAnimated:), the first view will appear rotated (unexpected!).

如果用户将设备旋转回纵向,视图将旋转,然后像以前一样陷入纵向模式。这有效,但在用户旋转之前它对用户来说很难看。所以我正在寻找一种方法让这个视图保持纵向模式。

If the user rotates the device back to portrait orientation, the view will rotate and then be stuck in portrait mode as before. This works but it's ugly for the user until they rotate back. So I'm in search of a way to make this view stay in portrait mode.

到目前为止我找到的唯一解决方法是使用 - [UIDevice setOrientation:] ,它会抛出一个警告( orientation 是只读的),但是因为实际定义了它所以有效。这是一个巨大的黑客,我想要一个真正的解决方案。为了寻找真正的解决方案,我将GDB附加到Photos应用程序(MobileSlideshow.app)并发现它也使用 - [UIDevice setOrientation:] 。作为一个内部应用程序虽然我猜他们有不同的规则。

The only workaround I have found so far is to use -[UIDevice setOrientation:], which throws a warning (orientation is read-only) but works since it is actually defined. This is a huge hack and I'd like a real solution. In search of a real solution I attached GDB to the Photos application (MobileSlideshow.app) and discovered that it too uses -[UIDevice setOrientation:]. Being an internal application though I guess they have different rules.

是否有正确的方法来实现预期的自转行为?

Is there a correct way to achieve the expected autorotation behavior?

推荐答案

我正打算告诉你,可能没有办法,但后来我有了一个想法。很难做到正确,但如果您使用两个单独的 UINavigationController s:一个控制根视图并禁止旋转,则可以使它工作正常对于允许它的子视图。您将手动处理与根控制器和子控制器之间的转换。

I was about to tell you that there was probably no way, but then I had a thought. It would be difficult to get right, but you might be able to make it work if you used two separate UINavigationControllers: one that controls the root view and prohibits rotation, and one for the child views that allows it. You would manually handle the transition to and from the root controller and the child controller.

您必须修补子导航控制器以获得正确的后退按钮。而且,当然,您必须自己处理后退按钮。您可能必须使用虚拟 UINavigationBar 来从一个导航控制器到下一个导航控制器执行动画,以便过渡看起来正确。您还必须为导航控制器之间的推送过渡设置动画,这可能需要进行一些调整才能使其看起来正确。您必须:

You'd have to patch up the child navigation controller to have the correct back button. And, of course, you'd have to handle the back button press yourself. You would probably have to use a dummy UINavigationBar to do the animation from one navigation controller to the next so that the transition will look right. You would also have to animate the "push" transition between the navigation controllers, as well, which might take a bit of tweaking to get it to look right. You would have to:


  1. 配置虚拟导航栏以与传出导航控制器完全匹配,并将其直接放置在导航控制器栏的顶部。 (您可以复制当前视图控制器的 UINavigationItem 的配置并将其推开)

  2. 将新导航控制器放在屏幕上右边缘

  3. 动画新旧控制器框架从右到左的移动

  4. 创建 UINavigationItem 用于传入视图控制器并将其推送到虚拟导航栏上

  5. 当动画完成时,删除虚拟 UINavigationBar 以及传出导航控制器。

  1. Configure a dummy navigation bar to exactly match the outgoing navigation controller's and place it directly on top of the navigation controller's bar. (You could copy the configuration of the current view controller's UINavigationItem and push it on)
  2. Place the new navigation controller off-screen at the right edge
  3. Animate the movement of the new and old controllers' frames from right to left
  4. Create a copy of the UINavigationItem for the incoming view controller and push it on the dummy navigation bar
  5. When the animation completes, remove the dummy UINavigationBar from the view, and also the outgoing navigation controller.

所有这些都是很多工作,但如果你非常聪明(而且非常顽强),你或许可以让它发挥作用。我很想看到结果!

All of this is a lot of work, but if you're very clever (and very tenacious), you might be able to get it to work. I'd love to see the result!

这就是说,你可能最好只使用 setOrientation:和利用App Store批准程序抓住机会; - )

That said, you might be better off just using setOrientation: and taking your chances with the App Store approval process ;-)

这篇关于UINavigationController和autorotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆