Question

I've been working on updating a few apps to support iPhone 5. They've had some layout issues that might be explained by the UIWindow always having the frame of an iPhone 5 regardless of the device it is run on. For a universal application for example the frame of the UIWindow gets set to (0, 0, 320, 568) even on an iPad. I am wondering what causes this and if this is really what I should be concerned with.

Was it helpful?

Solution

I have never checked this myself on universal applications, however make sure that:

  1. The window is already part of the view hierarchy. A newly created window won't help you with determining the size (you say you log frame "at the very beginning of -applicationDidFinishLaunching:").

  2. The frame is just an accessor which merges bounds and center properties. It doesn't work correctly if transforms are applied to the view (window). However, with a window, it's typical that a transform is applied.

The iOS drawing code for a window looks similar to the following:

CGContextSaveGState(context);
CGContextTranslateCTM(context, [window center].x, [window center].y);
CGContextConcatCTM(context, [window transform]);
CGContextTranslateCTM(context,
     -[window bounds].size.width * [[window layer] anchorPoint].x,
     -[window bounds].size.height * [[window layer] anchorPoint].y);

[[window layer] renderInContext:context];
CGContextRestoreGState(context);

(See Technical Note QA1703)

You can see that the final frame size is determined from bounds and transform. If you do some experiments, you can see that, for example, the keyboard window never changes bounds, even when device orientation is changed. The size change between portrait and landscape orientations is determined by the transform.

In general, window.rootViewController.bounds is the way to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top