SAR392
SAR392

Reputation: 185

Xcode 6 iOS 7 view size

My root view controller is a tab view controller. My app is landscape mode only. It's set on landscape both in the project settings and in the storyboard for each VC including the root. In viewDidLoad, I have:

NSLog(@"width of view in didappear:%f",self.view.frame.size.width);

and the same code in viewDidAppear. In viewDidLoad in iOS 8, that line prints out 480. In iOs 7, it prints out 320(the width of the screen in portrait mode) but in viewDidAppear, it prints out 480 which is correct. Yes it is the same device for all of you out there who are always in search of 'precise' details.

Why is the view still in portrait in viewDidLoad in ios7 but not in ios8? What can be done? I set up my whole view in viewDidLoad because I only need to do it once and so can't migrate it to viewDidAppear or other places.

Upvotes: 0

Views: 83

Answers (4)

Giwan
Giwan

Reputation: 1590

It's a curious difference between iOS 7 and 8 if that's the case. I'm guessing it's the same device type but physically different items? Or are you really running iOS 7 & 8 on the same device?

So you could theoretically still have setting differences. I.e. iOS 7 device locked in portrait, etc.

If the setup is really as you say, a boolean property would help you to run in viewDidAppear. I just provided an example of how that could be done here: https://stackoverflow.com/a/27867549/1111233

Upvotes: 1

Jorn
Jorn

Reputation: 1044

The frame is relevant to the parent view. The very top view is UIWindow, which in iOS 8 became rotation dependent. In landscape the frame and the bounds will therefore be different in iOS 7, but the same in iOS 8. If you use bounds instead of frame, it should give the same result for both iOS versions, given that the objects are not rotated some number of degrees.

Upvotes: 0

myte
myte

Reputation: 877

use bounds

CGRect rect = [[UIScreen mainScreen] bounds];

NSLog(@"width of view in didappear:%f",rect.size.width);

Upvotes: 0

Alex
Alex

Reputation: 3971

Basically, viewDidLoad is run before the UIElements are loaded and placed on screen, so that's why you are getting the wrong size. As far as the difference between iOS7 and iOS8, I guess apple slightly changed the internals, but in any case you should definitely move your graphics code to viewWillAppear. viewWillAppear is run when the graphics are loaded and works the same as viewDidLoad

Upvotes: 0

Related Questions