iphone - UINavigationController 和备用景观

标签 iphone cocoa-touch ios uinavigationcontroller

在我的应用程序中,我使用了备用景观界面策略(将您的景观 View 呈现为模态)。我还使用导航 Controller 进行转换,这会导致以下问题:我不知道如何从横向方向正确地推送/弹出。

我提出了以下解决方案,但有人可能知道更好的解决方案。假设只需要处理两个 View 。我们称它们为 AP、AL、BP、BL,其中第二个字母代表方向。我们从一个内置 AP 的导航 Controller 开始。要在 AP 和 BP 之间移动,我们只需推/弹出。为了从 AP 到 AL,我们提供了一个内置 AL 的模态导航 Controller 。为了在 AL 和 BL 之间移动,我们在 second 导航 Controller 中推送/弹出。现在从 BP 到 BL,我们弹出没有动画,并呈现一个模态导航 Controller ,其中 BL 位于 AL 之上。为了从 BL 转到 BP,我们关闭模态导航 Controller 并插入 BP 不带动画。

好像有点丑,但也不算太差。谁能想到更好的东西?

提前致谢!

最佳答案

您是否出于某种原因需要在单独的 Controller 中将横向显示为模态?当我有两个完全不同的纵向和横向 View 时,我会随着它们在旋转过程中拉伸(stretch)而在它们之间淡化。

这允许在两个方向上呈现截然不同的内容、它们之间的良好过渡以及在一个 Controller 下共享代码。

这是一些代码。当我们改变方向时,我们的 UIViewController 将在 portraitViewlandscapeView 之间切换。

portraitViewlandscapeView 都是 UIViewController 的 View 的子级。层次结构如下所示:

UIViewController
    |
     - view
        |
        |- portraitView
        |
        |- landscapeView

两者都有它们的autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight 以确保它们在 View Controller 旋转时拉伸(stretch)。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if( orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight )
    {
        [UIView animateWithDuration:duration
                         animations:^
                         {
                             //Fade the landscape view over the top of the 
                             //portrait view as during rotation 
                             landscapeView.alpha = 1.0f;
                         }
                         completion:^(BOOL finished)
                         {
                             //Hide the portrait view when landscape is fully
                             //visible
                             portraitView.alpha = 0.0f
                         }];
    }
    else
    {
        //Show the portrait view (underneath the landscape view)
        portraitView.alpha = 1.0f;

        [UIView animateWithDuration:duration
                         animations:^
                         {
                             //Fade out the landscape view to reveal the portrait view
                             landscapeView.alpha = 0.0f;
                         }];
    }
}

您的控件和 subview 将与相应的 View 一起淡入淡出和停用,让您拥有完全不同的内容。我最近使用它在改变方向时在两个不同的背景图像之间淡入淡出。效果很流畅。

您现在可以创建两个 View Controller ,AB,它们分别管理两个 View ,如上所述。然后,您可以像往常一样简单地推送 View Controller ,而不必担心在旋转期间管理 UINavigationController 的 View Controller 堆栈。

关于iphone - UINavigationController 和备用景观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6091230/

相关文章:

objective-c - 使用 ARC 声明委托(delegate)属性的推荐方法

Objective-C performSelectorInBackground - 调用的方法在哪里运行?

objective-c - 邮件和消息 Controller 的奇怪行为 - 预初始化

ios - 基于逻辑快速进行Segue

iphone - 在 iOS 中显示多个 View 的最佳实践

iPhone 自定义电话联系人的电话响铃方式

iphone - 裁剪图像使图片向左旋转

objective-c - 我想从 UIImagePicker 同时上传图像和视频

ios - 将 UISearchController 与 UINavigationController 一起使用

ios - 如何在 iOS 真机上调试 React Native 项目?