我在我的应用程序中使用导航 Controller 。我希望我的所有 viewController 都是纵向的,除了一个支持横向。
根据 Stack Overflow 中接受的答案,我将我的导航 Controller 子类化并包含以下代码:
iOS 6 - Navigation Controller Landscape Rotations For Some Views While Others Portrait Only
- (BOOL)shouldAutorotate {
id currentViewController = self.topViewController;
if ([currentViewController isKindOfClass:[IssueViewController class]])
return YES;
return NO;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
这会挑出我想要旋转的一个 View Controller 。一切都很好,除了当我横向启动应用程序时。图像被压碎并偏离中心。
屏幕截图在这里:http://imgur.com/a/jyrJ2
关于纠正这个问题有什么建议吗?谢谢!
最佳答案
测试了你的代码。这仅在您更改方向时工作正常,但如果您横向启动应用程序或横向从一个 Controller 切换到另一个 Controller ,它不会根据当前界面方向反射(reflect)更改。
使用以下方法,我之前曾用它来解决过同类问题。
在 UINavigationController 子类中添加这段代码
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
然后在您的 ViewController 中添加此代码
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
//Control UIInterfaceOrientationMask here to tell which interface orientations you want to support for this ViewController
return UIInterfaceOrientationMaskPortrait;
}
关于ios - 在某些 Controller 中禁用横向时,横向启动应用程序会扭曲整个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27050700/