iOS6.0旋轉(zhuǎn)兼容的那點(diǎn)事
這兩天問答系統(tǒng)里,問ios橫豎屏切換、還有狀態(tài)欄旋轉(zhuǎn)的問題有點(diǎn)多,來些小心得,希望遇到的人少走彎路;
先貼官方說明:
iOS 6.0 Release Notes:
Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method
of UIViewController is deprecated.In its place, you should use the supportedInterfaceOrientationsForWindow:
and shouldAutorotate methods.
在iOS 6.0之前我們都是使用shouldAutorotateToInterfaceOrientation方法來控制視圖、狀態(tài)欄的旋轉(zhuǎn),但是iOS 6.0及以后
就要使用supportedInterfaceOrientations方法來控制旋轉(zhuǎn)了;
所以向iOS 6.0兼容的需要手動添加supportedInterfaceOrientations 方法,來控制視圖和 狀態(tài)欄的旋轉(zhuǎn),還有兩點(diǎn)需要說明:
1、在iOS 6.0之前,控制旋轉(zhuǎn)的代碼,無需和plist的中的Supported interface orientations一一對應(yīng),舉個(gè)例子:
plist的Supported interface orientations選項(xiàng)中支持,Portrait(bottom home button)、Landscape(right home button),無Landscape(left home button)
方法shouldAutorotateToInterfaceOrientation中強(qiáng)制支持UIInterfaceOrientationLandscapeLeft編譯執(zhí)行沒有任何問題,
但是在iOS 6.0中,如果在supportedInterfaceOrientations中添加UIInterfaceOrientationMaskLandscapeLeft編譯正常,
運(yùn)行過程中,左旋轉(zhuǎn)程序就會異常退出;所以程序支持旋轉(zhuǎn)的,代碼與plist一定要保持一致;
2、在Xcode 4.5之前旋轉(zhuǎn)支持的是
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
而Xcode 4.5 GM Seed及Xcode 4.5.1旋轉(zhuǎn)支持的是(多了個(gè)All,還有Mask的修飾,Xcode 4.5之前是不識別的)
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskPortraitUpsideDown