简体   繁体   English

iPad横向显示肖像框和边界

[英]iPad landscape showing portrait frame and bounds

I am developing iPad landscape app using storyboard. 我正在使用故事板开发iPad景观应用程序。 I have done below steps for same. 我已经按照以下步骤进行了操作。 My app is screen is opening in Landscape on simulator.. But getting wrong frame. 我的应用程序正在模拟器的“横向”中打开屏幕。

  1. Sample app template from xcode for storyboard. xcode中用于演示图板的示例应用模板。
  2. Allow only landscape orientation from info-plist file 仅允许info-plist文件中的横向
  3. Storyboard -> UIViewController -> Simulated matrices -> Changed orientation to Landscape 故事板-> UIViewController->模拟矩阵->方向更改为横向
  4. Implemented below method in view controller.m 在view controller.m中实现以下方法

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

Now when I take NSLog of frame and bounds it show me portrait frame. 现在,当我取框架的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));
   }

Result Log : 结果日志:

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

   frame ::{{20, 0}, {748, 1024}}

Am I missing anything ? 我有什么想念的吗?

In viewDidLoad method you dont get correct bounds. 在viewDidLoad方法中,您不会获得正确的边界。 You do it in viewDidAppear method. 您可以在viewDidAppear方法中进行操作。 viewDidAppear method is called when view is loaded fully and has correct bounds. 当视图完全加载并具有正确的边界时,将调用viewDidAppear方法。

Try setting this and see the output. 尝试设置此项,然后查看输出。

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

frame ::{{20, 0}, {1024, 748}} 框架:: {{20,0},{1024,748}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM