iPad 横向显示纵向框架和边界

Swa*_*nil 2 objective-c ios

我正在使用故事板开发 iPad 横向应用程序。我已经完成了以下步骤。我的应用程序是在模拟器上的横向模式中打开屏幕.. 但得到错误的框架。

  1. 来自 xcode 的用于情节提要的示例应用程序模板。
  2. 仅允许来自 info-plist 文件的横向
  3. 故事板 -> UIViewController -> 模拟矩阵 -> 将方向更改为横向
  4. 在 view controller.m 中实现以下方法

           - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
        {
         // Return YES for supported orientations
       return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); 
            } 
    
    Run Code Online (Sandbox Code Playgroud)

现在,当我获取框架和边界的 NSLog 时,它会显示我的肖像框架。

   - (void)viewDidLoad
  {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"bounds ::%@",NSStringFromCGRect(self.view.bounds));
    NSLog(@"frame ::%@",NSStringFromCGRect(self.view.frame));
   }
Run Code Online (Sandbox Code Playgroud)

结果日志:

   bounds ::{{0, 0}, {748, 1024}}

   frame ::{{20, 0}, {748, 1024}}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

Dur*_*sad 5

在 viewDidLoad 方法中,您没有得到正确的边界。您可以在 viewDidAppear 方法中执行此操作。viewDidAppear 方法在视图完全加载并具有正确边界时调用。