Why wrong window size:

Using XCODE7 and iOS9 on an iPhone 5 shows the app with 320x480 size:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


Debugging self.window says: frame is (0,0,320,480) on an iPhone 5 Model !?


Is there anything else to do ?

The app was running correctly under iOS8.

Replies

I have a similar issue: in one of my view controller's viewWillAppear, self.view.frame has a size of 320x568 when using Xcode 6/iOS 8, but only 320x480 when using Xcode 7 beta/iOS 9. In both cases I'm testing in the simulator for iPhone 6. Any ideas why this is happening?

Does your app launch in landscape?

I think I'm seeing the same thing. I am getting screen dimensions of 320.0 X 480.0 when I call UIScreen.mainScreen().bounds in portrait orientation, regardless of whether I use iPhone 4S, iPhone 5 or iPhone6 simulator. I expect these dimensions on iPhone 4S, but not on the other platforms. On the 5 and 6, the app presents with black bars at the top and bottom. My code was working correctly prior to iOS 9 / XCode 7 / OS X 10.11 / Swift 2.0.

It was mentioned in one of the sessions that you no longer need to use -initWithFrame: when creating your windows. Call -init and the system will "do the right thing". Worth a shot.

Dex, I tried calling init() (I'm working in Swift, but init() should be equivalent to -init). If I call super.init from my UIView subclass, I get "Must call a designated initializer of the superclass 'UIView'". If I try to override init(), I get "Initializer does not override a designated initializer from its superclass". This leads me to believe -init is not (yet) a viable alternative. I haven't heard the session where they mentioned that -initWithFrame: was no longer needed, but that would be awesome because it's never made sense to set a frame when using auto-layout. Maybe this change is just not in the current build yet?

I think your confusing what the recommendation is.


For iOS 9 applications, when creating a UIWindow in code, it is recommended that you use -init, as that method will create a window that is full sized for your application's current multitasking bounds. This however does not extend to UIView – -[UIView init] creates a zero sized view. If you are subclassing UIView (which it sounds like your latter comments say) then you need to override the designated initializers, -initWithFrame: and -initWithCoder:.


However, to answer the original question, the likely answer is you don't have the correct launch images. A new project in Xcode will configure correctly for all of this and should always give you a fullscreen window at the device's natural size. If you are updating a current application, you will likely want to emulate what Xcode does for its default projects.

I am having the same problem with a project that is done completely programmatically with my AppDelegate written in Swift. I don't have any launch images yet either. This has always worked correctly for previous versions of XCode. I also changed the window initialization to be UIWindow() as a previous poster indicated. I am testing on an iPhone 5s.

If you don't have any launch images, and you don't have a launch nib or storyboard, then you are declaring that you don't support any screen sizes aside from 320x480 (on iPhone/iPod). This has always been the case and is not new. Older Xcode Projects automatically generated a Default-568h.png to support 4" screens. This may have been invisible if you've used an iPhone 6 or iPhone 6 Plus, because if you had a Default-568h.png for 4" screen support, these devices scaled your app rather than letter boxed them.


A brand new project should not demonstrate any of these issues.

This reduced screen size appears related to launch images set for the device. Update your launch images to be all the right sizes and the size issue goes away. There is a note somewhere in XCode7 that mentions this area.

I added a launch image storyboard and that fixed it. thanks!

Why would an existing app that works correctly in iOS7 & iOS8 suddenly start rendering letterboxed? Our company's application has been running fine on all support iOS versions, and now on iOS9 it is getting truncated. IS iOS9 not backwards compatible? When everyone upgrades tomorrow, will their version of our application start getting letterboxed?


Please provide any insight.

You will have to better define "existing apps".


If by existing app you mean your application built against the iOS 8.4 or earlier SDK deployed to the store, then they should work as you might expect – they are running in a compability mode. The compatibility mode may not be perfect, but I wouldn't expect letter boxing for example.


However, if you build your application with the iOS 9 SDK, you are no longer in any compatiblity modes, and we are no longer compensating for changes made between 8.4 and 9.0. This may cause your application to break and you should test and modify your application before you next submit it.

What if I don't use launch images? Why it's not an issue for iPad?

If you don't use launch images, but you do have a Launch Screen (nib or storyboard) then we synthesize your launch screen at install time. It isn't an issue for iPad because up until the iPad Pro was introduced, iPad has only had 1 virtual screen size (768x1024) and thus didn't need anything to differentiate fullscreen support. With the iPad Pro you will need a Launch Screen to support the new screen size (and you need Launch Screens to support multitasking on iPad in general).

I'm having the same issue. Any solution to this?