iOS 6 : Parent modal's modalPresentationStyle ignored after rotation

标签 ios ipad rotation modal-dialog

对于 iOS6 的 iPad,我们有一个错误,模态视图 Controller 将扩展到全屏,即使它被告知 使用“表单”演示文稿样式。但是,只有当有两个模态,一个父模态和它的子模态时,才会发生这种情况。

这就是第一个模态框的创建和呈现方式:

UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is my application's root controller

子模态是这样创建和呈现的:

UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is the navigationController from above

因此,当从横向旋转到纵向时,父模态将扩展到全屏并保持这种状态,即使我们旋转回横向也是如此。

当我们只有父模态(没有子模态)时,它会按预期工作,即它保持表单样式。

请注意,这种情况只发生在 iOS6(设备和模拟器)上,不会发生在 iOS 5(模拟器,测试人员报告它可以工作)上。

到目前为止,我已经尝试了以下但没有成功:

  • wantsFullScreenLayout设置为NO
  • 强制 wantsFullScreenLayout 通过覆盖它总是返回 NO
  • 确保我的导航 Controller 内的 Controller 也指定 UIModalPresentationFormSheet
  • 实现preferredInterfaceOrientationForPresentation
  • 升级到 iOS 6.0.1

谢谢!


更新: 因此,我调整了 Apple 开发者论坛 ( https://devforums.apple.com/message/748486#748486 ) 的回复,使其适用于多个嵌套模式。

- (BOOL) needNestedModalHack {
    return [UIDevice currentDevice].systemVersion.floatValue >= 6;
}

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                          duration:(NSTimeInterval)duration {

    // We are the top modal, make to sure that parent modals use our size
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
        for (UIViewController* parent = self.presentingViewController;
             parent.presentingViewController;
             parent = parent.presentingViewController) {
            parent.view.superview.frame = parent.presentedViewController.view.superview.frame;
        }
    }

    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                 duration:(NSTimeInterval)duration {
    // We are the top modal, make to sure that parent modals are hidden during transition
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
        for (UIViewController* parent = self.presentingViewController;
             parent.presentingViewController;
             parent = parent.presentingViewController) {
            parent.view.superview.hidden = YES;
        }
    }

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    // We are the top modal, make to sure that parent modals are shown after animation
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
        for (UIViewController* parent = self.presentingViewController;
             parent.presentingViewController;
             parent = parent.presentingViewController) {
            parent.view.superview.hidden = NO;
        }
    }

    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

最佳答案

不确定这是否应该被视为一个错误,我很好奇 iOS 7 会带来什么,但此问题的当前解决方法是将 modalPresentationStyle 设置为 child-viewController 的 UIModalPresentationCurrentContext。

Set modalPresentationStyle = UIModalPresentationCurrentContext

这使得子项仍然显示为 FormSheet,但阻止父项在旋转时调整为全屏。

德克

关于iOS 6 : Parent modal's modalPresentationStyle ignored after rotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13347906/

相关文章:

c++ - 不使用OpenCV函数在C++中旋转图像

java - 将 JLabel 旋转 90 度 Java

javascript - jquery 旋转在 ie 中不起作用

ios - 在方法中返回完成处理程序之前如何等待委托(delegate)完成?

javascript - 视频海报在 iPad 2 上播放一次后消失

iphone - 当 iPad 日期时间设置更改时通知应用程序

javascript - iPad JS 上的闪存

ios - 如何快速停止音频播放器

ios - 来自 UI 控件的奇怪 Bool 类型

ios - 尝试创建一个 Xcode Objective-C 函数来记录我的 UIView 内容的视频捕获并保存到手机