View controller frame.height and frame.width are replaced for iOS 8

I am updating an application that works in landscape, and I am testing in a simulator and on an iPhone 5 running iOS 8. The results of my view controller value for self.view.frame.size.width are the values ​​I always got for self.view .frame.size.height in iOS 7 and earlier. Many elements now show that the x and y coordinates are now inverted, respectively.

I'm looking for an elegant solution that resembles the previous behavior, maybe this is not possible in iOS 8 in landscape mode?

+5
source share
3 answers

As user nyekimov pointed out, this is a new iOS 8 behavior. Something was connected at the 2014 WWDC session. I hope this link helps :) To solve the problem, I just added iOS 8 and iPad checks and changed the width to height. (I just got this problem on the iPad, so I did just that)

Good luck !: D

+4
source

I ran into the same problem with my application, which also works exclusively in landscape mode - I just used the if statement to fix the problem wherever it occurs.

if (self.view.frame.size.height> self.view.frame.size.width) {then you are using iOS versions <8, and the API still refers to portrait sizes. use existing code. } else {you are using iOS 8 and you will need to change your links to width and height}

If your application switches to orientation, you may also need to capture the orientation of the device - see device orientation

Hope this helps.

0
source

If we try to access the width and height values ​​from self.view.frame.size in viewWillLayoutSubviews instead from viewWillAppear: give the correct values.

It worked for me :)

0
source

Source: https://habr.com/ru/post/1202921/


All Articles