1

I've spend the past three days trying to figure out the iOS-6 autorotation mess, and have not arrived at a solution.

It's relatively straight-forward to have an app where all views rotate, or where rotation is completely disabled. And (conveniently for our needs) if you use a MPMoviePlayerViewController it will autorotate even if the app has autorotation disabled.

But having conditional autorotation, where some views are allowed to rotate and others are not, is elusive. I can achieve conditional autorotation (by having the root view controller "consult" the top view controller to determine what rotation it permits), but when the rotated view is exited it leaves the prior view rotated (when previously it had not been). This is not acceptable.

Has anyone cracked this nut?

(Like I told my boss, if you want a wider view you should just put wider paper in the printer.)

Further problem: Having gotten the basic conditional rotation to work (see comments below), I find that it hoses some screens in the "right wrong" circumstances. On this non-rotatable screen I press "Intro" to go to a rotatable one.

enter image description here

On the rotatable screen I rotate it, then return from it with it rotated. When I get back I have this screen:

enter image description here

The XIB file is pretty vanilla:

enter image description here

The errant piece appears to be the "Image View -- img_hea..." element which for some reason gets "amplified" vertically about 4x. There is no logic moving/resizing elements in the view (other than the standard UITableView stuff), and no reference at all to the problem UIImageView.

With an NSLog placed in viewWillAppear I see that the UIImageView is dimensioned 320x44 initially but 320x160 on return from the rotated screen.

This looks like an out-and-out Apple bug.

More: If I make the problem screen rotatable and rotate it right/left (back to portrait) the image is screwed up. I'm guessing that iOS "returns" to the screen before rotating back, and that's why it gets mucked up. Interestingly, in the rotated view the UIImageView is not showing up at all, with the Y dimension coming out zero in the NSLog.

Also, now that I notice it, the label that had been superimposed over the problem image is gone altogether in both rotated and post-rotation views.

OK: Turned off "Autoresize Subviews" for the overall UIVIew, and that makes things work correctly. This is the second time I've found the "Autoresize Subviews" XIB attribute causes flaky behavior.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
  • OK, I finally happened across [this answer](http://stackoverflow.com/a/13090766/581994). (It always happens just after you post the question, it seems.) It's not pretty, but it seems to work, at least for the simple case. Basically, in the VC "below" the rotatable one you implement `supportedInterfaceOrientation` and return the mask with only one orientation. Having `supportedInterfaceOrientation` implemented in the "non-root" VC doesn't appear to have any affect/function in any other context. – Hot Licks Dec 10 '12 at 21:37
  • Possible duplicate of *[iOS 6: How do I restrict some views to portrait and allow others to rotate?](http://stackoverflow.com/questions/12630359/ios-6-how-do-i-restrict-some-views-to-portrait-and-allow-others-to-rotate)*. – Peter Mortensen Oct 05 '13 at 20:10
  • Not the most elegant of solutions but here is an [answer](http://stackoverflow.com/a/13090766/1354100) from another question that might work for you. – Bejmax Dec 10 '12 at 21:37

0 Answers0