objective-c - 强制 Controller 更改纵向或横向方向

标签 objective-c ipad cocoa-touch

我有以下 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/

相关文章:

iphone - 如何以编程方式关闭键盘?

iphone - 删除 quartz 2d 中上下文中的剪辑

iphone - UITextView 在 iPhone 中隐藏键盘

objective-c - 如何在 Xcode 4.2 上启用 Objective-C 异常?

objective-c - 用另一个数组过滤的数组(CS 和谓词)

ios - 在触摸期间停止 UIScrollView 滚动

jquery - 如何在iPad上实现dblclick事件

ios - UISplitViewController 多个细节 View 分段控制

iphone - UITextView 委托(delegate)类在单击 TextView 时崩溃?!这是怎么回事?

iOS 6 - 响应键盘完成按钮状态