gpt4 book ai didi

ios - UIModalPresentationCustom 搞乱了方向设置

转载 作者:行者123 更新时间:2023-12-01 16:38:43 24 4
gpt4 key购买 nike

使用 UIModalPresentationCustom 呈现模态时, 它忽略方向方法,并显示/旋转到任何呈现 VC 配置的位置。

例子:

  • Presenting VC 支持横向和纵向。
  • 介绍的VC支持纵向仅限 (通过 preferredInterfaceOrientationForPresentationsupportedInterfaceOrientations

  • 在没有 UIModalPresentationCustom 的情况下以横向呈现时,它将 View 旋转回纵向,然后相应地呈现 VC。不幸的是,因为我需要展示的 VC 在下方保持可见,我不得不使用 UIModalPresentationCustom .当这种情况发生时,呈现的 VC 被迫进入横向模式,创建一个困惑的 UI 并产生约束问题。并且即使在纵向呈现时,它也可以旋转成横向,忽略 shouldAutorotate返回 NO。

    PS:通过将此方法添加到我的 App Delegate 中,我在 iOS 7 上找到了一种解决方法,但在 iOS 8 上并没有修复它。
    @implementation UIViewController (customModalFix)

    - (BOOL)shouldAutorotate
    {
    if ([self.presentedViewController isKindOfClass:[IntroViewController class]]) {
    return [self.presentedViewController shouldAutorotate];
    }
    return YES;
    }

    @end

    编辑 : 实现 supportedInterfaceOrientations在呈现 VC 上根本没有帮助,因为它仅在加载 View 时调用,而不是在即将在其上呈现 VC 时调用。仍然没有找到解决这个问题的方法。

    最佳答案

    也许我迟到了。重点是,在使用 UIModalPresentationCustom 时,呈现的 VC 不会消失,呈现的 VC 也不会被认为是全屏呈现(即使确实占据了全屏)。因此,为支持的界面方向咨询的是呈现的 VC。所以解决方案可以是:

    - (NSUInteger)supportedInterfaceOrientations
    {
    if (self.presentedViewController) {
    return [self.presentedViewController supportedInterfaceOrientations];
    }
    return [super supportedInterfaceOrientations];
    }

    关于ios - UIModalPresentationCustom 搞乱了方向设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26061514/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com