简体   繁体   English

iPad Landscape View框架尺寸

[英]iPad Landscape View frame size

When I use ViewController.View.frame.size.width and height in landscape mode, I am getting 768 and 1024 respectively where as I see 1024 and 768 from my Storyboard's "Size Inspector". 当我在横向模式下使用ViewController.View.frame.size.width和height时,我分别得到768和1024,我在Storyboard的“Size Inspector”中看到了1024和768。 Have anyone got any idea why this is happening? 有谁知道为什么会这样?

This is an oddity (bug?) in iOS. 这在iOS中是一个奇怪的(错误?)。 But I'd wager that so many people have done kludgy workarounds (eg, inspect the device orientation and if landscape, flip the width and height ), that I'm not sure if Apple dare fix this, for fear of breaking tons of apps. 但我敢打赌,有这么多人做了大量的解决方法(例如,检查设备方向,如果是横向,翻转widthheight ),我不确定Apple是否敢于解决这个问题,因为担心会破坏大量的应用程序。

As an example of the strange behavior, if you have a navigation controller, for example, you'll find that the frame.size is correct as you go from portrait to landscape mode, but in the absence of a navigation controller, it isn't. 作为奇怪行为的一个例子,例如,如果你有一个导航控制器,你会发现当你从纵向到横向模式时frame.size是正确的,但是在没有导航控制器的情况下,它不是吨。 If you're just looking for the width and height, you can frequently grab bounds.size , instead, which appears to get updated properly, regardless. 如果你只是在寻找宽度和高度,你可以经常抓住bounds.size ,相反, bounds.size都可以正确更新。

You cannot use the frame for a view's dimension. 您不能将frame用于视图的尺寸。 You have to use bounds . 你必须使用bounds More info is here: My self.view has the wrong dimensions 更多信息在这里: 我的self.view有错误的尺寸

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

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