iOS-6 — How to achieve conditional autorotation?

旧城冷巷雨未停 提交于 2020-01-15 10:33:33

问题


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.

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

The XIB file is pretty vanilla:

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.

来源:https://stackoverflow.com/questions/13809409/ios-6-how-to-achieve-conditional-autorotation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!