我有以下 Controller ,(我已在 iPad 中选择了所有类型的方向模式)
这是我的 iPad Storyboard布局
Custom NavigationController > Loading Ctrl > Main Controller.
我的自定义导航包含
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
在我的加载 Controller 中
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
supportedInterfaceOrientations 像往常一样被调用,一切看起来都很好,但是当我使用 PerformSegue 推送我的主 Controller 时
-(NSUInteger)supportedInterfaceOrientations
{
if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
MainController 中不再有调用。这是为什么?
最佳答案
有一个技巧。
从应用程序中获取状态栏并旋转它。
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
以模态方式创建、显示和关闭一个空 View Controller 。
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
现在您的设备应该被迫旋转。您现在可以选择合适的 View Controller 或使用导航 Controller 推送 View Controller 。
关于objective-c - 强制 Controller 更改纵向或横向方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18957785/