(转)iOS 6的Rotation--详细版本
iOS 6的rotation改變了很多。先來看看官方的描述??http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/
?
知識點:
*UIViewController的shouldAutorotateToInterfaceOrientation方法被deprecated。在ios6里,是使用supportedInterfaceOrientations and shouldAutorotate 2個方法來代替shouldAutorotateToInterfaceOrientation。注意:為了向后兼容iOS 4 and 5,還是需要在你的app里保留shouldAutorotateToInterfaceOrientation。
for ios 4 and 5, 如果沒有重寫shouldAutorotateToInterfaceOrientation,那么對于iphone來講,by default是只支持portrait,不能旋轉。
for ios 6, 如果沒有重寫shouldAutorotate and supportedInterfaceOrientations,by default, iphone則是"可以旋轉,支持非upside down的方向",而ipad是"可以選擇,支持所有方向"
?
example 1: for ios 4 and 5, iphone device, 若要"可以旋轉,支持非upside down的方向",則可以在view controller里
?
[cpp]?view plaincopy
example 2: for ios 6, iphone device, 若要“不能旋轉,只支持portait",則可以在view controller里
?
?
[cpp]?view plaincopy
example 3: for ios 6, ipad device, 若要“可以旋轉,只支持landscape",則可以在view controller里
?
?
[cpp]?view plaincopy
?
* 在iOS 4 and 5,都是由具體的view controller來決定對應的view的orientation設置。而在iOS 6,則是由top-most? controller來決定view的orientation設置。
舉個例子:你的app的rootViewController是navigation controller "nav", 在”nav"里的stack依次是:main view -> sub view > sub sub view,而main view里有一個button會present modal view "modal view".
那么for ios 4 and 5,在ipad里,如果你要上述view都僅支持橫屏orientation,你需要在上面的main view, sub view, sub sub view, model view里都添加
?
[cpp]?view plaincopy
而對于iOS6, 由于是由top-most controller來設置orientation,因此你在main view, sub view, sub sub view里添加下面的代碼是沒有任何效果的,而應該是在nav controller里添加下列代碼。而modal view則不是在nav container里,因此你也需要在modal view里也添加下列代碼。
?
?
[cpp]?view plaincopy
注意:
?
*你需要自定義一個UINavigationController的子類for "nav controller",這樣才可以添加上述代碼。
* 和navigation controller類似,tab controller里的各個view的orientation設置應該放在tab controller里
?
for ios6的top-most controller決定orientation設置,導致這樣一個問題:在 top-most controller里的views無法擁有不相同的orientation設置。例如:for iphone, 在nav controller里,你有main view, sub view and sub sub view,前2個都只能打豎,而sub sub view是用來播放video,可以打橫打豎。那么在ios 4 and 5里可以通過在main view and sub view的shouldAutorotateToInterfaceOrientation里設置只能打豎,而在sub sub view的shouldAutorotateToInterfaceOrientation設置打豎打橫即可。而在ios 6里則無法實現這種效果,因為在main view, sub view and sub sub view的orientation設置是無效的,只能夠在nav controller里設置。那么你可能想著用下列代碼在nav controller里控制哪個view打豎,哪個view打橫
?
[cpp]?view plaincopy
是的,這樣可以使得在main view and sub view里無法打橫,而sub sub view橫豎都行。但問題來了,如果在sub sub view時打橫,然后back to sub view,那么sub view是打橫顯示的!
?
目前想到的解決方法只能是把sub sub view脫離nav controller,以modal view方式來顯示。這樣就可以在modal view里設置打橫打豎,而在nav controller里設置只打豎。
?
* 說了那么多,其實如果你的app的所有view的orientation的設置是統一的,那么你可以簡單的在plist file里設置即可,不用添加上面的代碼。而如果你添加了上面的代碼,就會覆蓋plist里orientation的設置。
?
* in iOS 6, 當view controller present時,不會call willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods,只有在發生rotate的時候才會call
?
出處:http://blog.csdn.net/totogogo/article/details/8002173
轉載于:https://www.cnblogs.com/goodleixiao/archive/2012/12/19/2824597.html
總結
以上是生活随笔為你收集整理的(转)iOS 6的Rotation--详细版本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android自定义退出弹出框
- 下一篇: 安卓学习之--如何关闭所有的activi