UINavigationController 和替代景观
在我的应用程序中,我使用备用景观界面策略(将景观视图呈现为模式)。我还使用导航控制器进行转换,这会导致以下问题:我不知道如何从横向正确推送/弹出。
我想出了以下解决方案,但有人可能知道更好的解决方案。假设一个人只需要处理两个视图。我们称它们为 AP、AL、BP、BL,其中第二个字母代表方向。我们从内部带有 AP 的导航控制器开始。要在 AP 和 BP 之间切换,我们只需压入/弹出即可。为了从 AP 到 AL,我们提出了一个内置 AL 的模态导航控制器。为了在 AL 和 BL 之间切换,我们在第二导航控制器内推送/弹出。现在,为了从 BP 转到 BL,我们弹出无动画并呈现一个模态导航控制器,其中 BL 位于 AL 之上。为了从 BL 转到 BP,我们关闭模态导航控制器并推送 BP(不带动画)。
看起来有点丑,但也没有那么糟糕。有人能想出更好的办法吗?
提前致谢!
In my application I use an Alternate Landscape Interface strategy (present your landscape view as a modal). I also use a navigation controller for transitioning and this causes the following problem: I dunno how to push/pop correctly from landscape orientation.
I came up with the following solution, but someone may know a better one. Suppose one has to deal with only two views. Let's call them AP, AL, BP, BL, where the second letter stands for orientation. We start with a navigation controller with AP inside. To go between AP and BP we just push/pop. To go from AP to AL we present a modal navigation controller with AL inside. To go between AL and BL we push/pop inside the second navigation controller. Now to go from BP to BL we pop w/o animation and present a modal navigation controller with BL sitting on top of AL. To go from BL to BP we dismiss the modal navigation controller and push BP w/o animation.
Seems to be a bit ugly, but not so bad. Can anyone think of something better?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否有某种原因需要在单独的控制器中将横向方向呈现为模态?当我的纵向和横向方向有两个完全不同的视图时,当它们在旋转过程中拉伸时,我会在它们之间淡出。
这允许两个方向上截然不同的内容、它们之间的良好过渡以及在一个控制器下共享代码。
这是一些代码。当我们改变方向时,我们的 UIViewController 将在 portraitView 和 landscapeView 之间切换。
portraitView 和 landscapeView 都是 UIViewController 的 view 的子级。层次结构如下所示:
两者都有其 autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight 确保它们随着视图控制器的旋转而拉伸。
您的控件和子视图将与相应的视图一起淡出和停用,从而使您可以拥有完全不同的内容。我最近使用它在改变方向时在两个不同的背景图像之间淡入淡出。效果非常流畅。
您现在可以创建两个视图控制器,A 和 B,每个控制器管理两个视图,如上所述。然后,您可以像平常一样简单地推送视图控制器,而不必担心在旋转期间管理 UINavigationController 的视图控制器堆栈。
Is there some reason you need to present your landscape orientation as modal in a separate controller? When I have two entirely different views for my portrait and landscape orientations I fade between them as they stretch during the rotation.
This allows for vastly different content in both orientations, a nice transition between them, and shared code under one controller.
Here is some code. Our UIViewController will switch between portraitView and landscapeView when we change orientation.
portraitView and landscapeView are both children of the UIViewController's view. The hierarchy looks as follows:
Both have their autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight to ensure that they stretch as the view controller rotates.
Your controls and subviews will fade and deactivate along with the appropriate views, allowing you to have completely different content. I used this recently to fade between two different background images when changing orientation. The effect is very smooth.
You can now create your two view controllers, A and B which each manage two views as described above. You can then simply push the view controllers as normal and not have to worry about managing the UINavigationController's view controller stack during rotation.