简体   繁体   English

将视图控制器frame.height和frame.width交换为iOS 8

[英]View controller frame.height and frame.width are swapped for iOS 8

I'm updating an app which runs in landscape and I'm testing in the simulator and on an iPhone 5 running iOS 8. The results from my view controller's value for self.view.frame.size.width are the values I've always received for self.view.frame.size.height in iOS 7 and earlier. 我正在更新一个可以横向运行的应用程序,并且正在模拟器中以及运行iOS 8的iPhone 5上进行测试。我的view controller的self.view.frame.size.width值的值就是我拥有的值在iOS 7及更低版本中始终收到self.view.frame.size.height的信息。 Many elements now show with the x and y coordinates now flipped accordingly. 现在显示的许多元素的x和y坐标都已相应翻转。

I'm looking for an elegant solution which gets the same behavior as before, perhaps this is not possible with iOS 8 in landscape mode? 我正在寻找一种优雅的解决方案,该解决方案具有与以前相同的行为,也许这对于横向模式下的iOS 8是不可能的?

As pointed by the user nyekimov, it's a new behavior of iOS 8. There was something related in WWDC 2014 Session 214. Hope this reference helps :) To solve the problem I just added a verification of iOS 8 and iPad and swapped the width with height. 正如用户nyekimov所指出的,这是iOS 8的新行为。WWDC 2014 Session 214中涉及到一些相关问题。希望此参考对您有所帮助:)为解决该问题,我添加了一个iOS 8和iPad验证并交换了宽度高度。 (I just got this problem on iPad, that's why I made only for it) (我刚刚在iPad上遇到了这个问题,这就是为什么我仅为此而做)

Good luck ! 祝好运 ! :D :D

I ran into the same issue with my application which also runs solely in Landscape mode - I simply used an if statement to correct the issue wherever it occurs. 我的应用程序也遇到了同样的问题,该应用程序也仅在横向模式下运行-我只是使用了if语句来纠正发生问题的地方。

if(self.view.frame.size.height > self.view.frame.size.width) { then you are using iOS versions < 8 and the API is still referencing portrait dimensions. if(self.view.frame.size.height> self.view.frame.size.width){则您使用的是iOS版本<8,并且API仍引用纵向尺寸。 use your existing code. 使用您现有的代码。 } else { you are using iOS 8 and you will need to alter your width/height references } }其他{您正在使用iOS 8,则需要更改宽度/高度参考}

If your application switches orientation then you may need to grab the orientation of the device also - see device orientation 如果您的应用程序切换了方向,那么您可能还需要抓住设备的方向 -请参阅设备方向

Hope this helps. 希望这可以帮助。

If we try to access the values of width and height from self.view.frame.size in viewWillLayoutSubviews instead from viewWillAppear: will give the proper values. 如果我们尝试从viewWillLayoutSubviews中的self.view.frame.size而不是viewWillAppear中访问width和height的值,则会提供适当的值。

This worked for me :) 这对我有用:)

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

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