ios - 横向模式下的导航 Controller 堆栈,但总是以纵向帧大小模态呈现 View Controller View

标签 ios

我的应用程序主要使用导航 Controller 堆栈,有时会模态显示一些 Controller 。在横向模式下,导航 Controller 堆栈中的 Controller 工作正常,但 presentViewController 或以前的 presentModalViewController 显示的其他 View Controller 始终提供纵向尺寸的 View 框架(在 iPad iOS 6.0 上始终为 768x1024) - 即使在纵向和横向之间来回旋转也是如此。

A view controller is in landscape mode, but I'm getting the frame from portrait mode? 相关的种类但是检查的答案没有帮助。如果我将稍后的 View Controller 添加为导航堆栈的一部分,则在第一次加载和后续旋转时会发生调整大小。如上所述,只有在通过 presentViewController 添加 Controller 时才会出现问题。

最佳答案

将模态分支包装到另一个导航 Controller 并在那里定义旋转掩码。
在 iOS6 中 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)仅适用于导航堆栈分支,整个分支应该以相同的方式工作。

因此,子类化导航:

@interface CLNotRotatingNavController : UINavigationController

并在其 .m 中添加此
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL) automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
    return YES;
}

并将所有模态分支包装到此导航。这将在必要时将所有内容锁定到横向。

关于ios - 横向模式下的导航 Controller 堆栈,但总是以纵向帧大小模态呈现 View Controller View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13108198/

相关文章:

iphone - iPhone OpenGL ES 2.0 中 glReadPixels 的更快替代品

ios - UICollectionView 中的 UILabel 跨越两个或多个单元格

ios - CoreImageContext 的 CreateCGImage 产生了错误的 CGRect

IOS 13 自动化要求运行

javascript - 从网页调用号码

IOS Swift,无法使用 NSPredicate 过滤 PHFetchOptions 中的隐藏照片

javascript - 将 JavaScript 评估到 WKWebView 中以获取视频 URL 不起作用

python - 如何使用数据库训练智能聊天机器人,然后添加到 iOS 应用程序

iOS UIImagePickerController 如何在从相机拍摄图像后立即保存图像

ios - 我忘记了 APNs 证书,现在怎么办? (推送通知不起作用)