ios - 如何强制 iPad 横向加载?

标签 ios objective-c uiview

我有一个支持 UIDeviceOrientationPortrait 和 UIDeviceOrientationLandscapeLeft 的 iPad 应用。

我确实包含了这个方法:

    - (BOOL)shouldAutorotateToInterfaceOrientation:        
      (UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait ||
        interfaceOrientation == UIInterfaceOrientationLandscapeLeft );
    }

我遇到的问题是我需要它以 UIDeviceOrientationLandscapeLeft 模式加载,只是为了加载,因为我的 UI 控件将被正确设置。我怎样才能在加载时只强制执行一次。

我要注意的一件事是,这必须是最低 iOS 5。

最佳答案

我最近遇到了类似的问题,但我想强行从 Landscape 更改为 Portrait,我知道在旧版本中有内置方法,但不幸的是我们永远不确定什么时候以及什么对我们有用,但我给出了这段代码尝试了一下,它对我有用,但我的场景是强制从横向到纵向,这与您的场景相反,但无论如何它都有效,这里是可能适用于您的场景的代码;

    -(NSUInteger)supportedInterfaceOrientations

{
    return UIInterfaceOrientationMaskLandscape;

}

-(void)viewWillAppear:(BOOL)animated {

    UIApplication* application = [UIApplication sharedApplication];

    if (application.statusBarOrientation != UIInterfaceOrientationLandscapeLeft)
    {
        UIViewController *c = [[UIViewController alloc]init];
        [self presentModalViewController:c animated:NO];
        [self dismissModalViewControllerAnimated:NO];
    }


    [super viewWillAppear:animated];
}

编辑 在 IOS 6.1 上工作我添加了两个我在之前的帖子中没有添加的方法,我现在添加所有适用于我的应用程序的方法...

- (BOOL)shouldAutorotate
{

    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

我的想法是检查状态栏方向并添加和关闭 modalViewController,它对我来说可以强制从一个方向转到另一个方向。

关于ios - 如何强制 iPad 横向加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14634682/

相关文章:

ios - SSKeychain 凭证存储设置不正确?

ios - 如何在使用 UIColor 设置背景时获取 View 的背景颜色或图像(图案图像 : UIImage(named :"myimage.jpg")) in swift

ios - 如何在单击时从一个 ViewController(包含自定义 UIView)移动到另一个 ViewController(包含 UITableView)?

iphone - 应用内购买沙箱测试错误

ios - SwiftUI 文本不会扩展为多行

ios - 使用 Google SignIN 登录时如何检索用户数据?

ios - Swift 可编码,当 JSON 中缺少键时,类属性的默认值

objective-c - 告诉自定义委托(delegate)何时调用方法

objective-c - 将排序描述符应用于从模板创建的 NSFetchRequest

iphone - 如何以编程方式创建 iOS 应用程序 View