Monday, December 22, 2008

More on UIAlertView and Landscape Problem

I created an Xcode project to illustrate the problem I'm having with UIAlertView. You can see the result here:


Here is the Xcode project to recreate this problem on your machine. It's pretty simple - but if someone sees that I've done something stupid, please feel free to call me out on it. In fact, I want to encourage it, so the first person who can show me something I've done wrong in this project that is causing this problem with UIAlertView is welcome to a free copy of Beginning iPhone Development, if they want it.



4 comments:

Gavin Bowman said...

It does show the wrong way for me in the project you sent. But, if you actually change the setting in the didFinishLaunching manually:-

[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

Then it'll show the right way.

Some issue with picking the value up from the plist maybe?

TC said...

And if you rotate the device, the application also figures out its current orientation.

Sounds like the application isn't fully aware of its current orientation if you specify the initial orientation in Info.plist. Maybe it's expecting to receive a notification that's not being sent?

Scott Squires said...

if you always return YES to autorotate and then rotate the device to portrait and back (or remove the plist landscape mode and allow rotation) then it works.

Evidently some else is required to make it work other than the plist setting. In re-reading the FAQ and guide it would appear you still have to apply a basic transform

FAQ
Setting this key does not rotate your interface; you still need to lay out your content in landscape mode and do the appropriate rotation using CFAffineTransform. For detailed information see "Launching in Landscape Mode" in iPhone OS Programming Guide.

Guide:
The UIInterfaceOrientation key provides a hint to iPhone OS that it should set the orientation of the
application status bar (if one is displayed) to the specified orientation at launch time. Using this key is
equivalent to calling the setStatusBarOrientation:animated: method of UIApplication early in
the execution of your applicationDidFinishLaunching: method. Setting this orientation affects only
the status bar orientation, however, and does not affect the orientation of your views or default launch image.
...
Therefore, the size of a view does not change its orientation
at load time; it is always loaded in portrait mode. It is up to you to rotate your views to the appropriate
orientation after they are loaded. When you do this depends on how you construct your application. If you
construct your application using view controllers, you can perform this operation in the viewDidLoad method
of your view controller objects. If you are not using view controllers, you can per form it in the
applicationDidFinishLaunching: method after creating your views or after loading them from a nib
file.

Jeff LaMarche said...

Gavin - Thanks you! That does do the job. If you want a copy of the book, drop me an e-mail with your postal address. Or, you can substitute a beer at MacWorld or WWDC if you prefer ;)

I think I'll leave the bug report open with Apple and just downgrade it to "Other Bug" - this doesn't seem like correct behavior even in light of the documentation Scott referenced. I did adjust the size of my view etc., but if setting the same value manually causes a different result, I'm thinking it's not the correct behavior.