我的应用程序主要使用导航 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/