IOS6 螢幕旋轉 以及 旋轉後的對應方法

2021-06-21 00:17:20 字數 1579 閱讀 5919

想要在ios6下支援螢幕旋轉,首先有一下兩點要求:

1、在 info.plist 中需要有supported inte***ce orientations支援(預設支援三個方向的旋轉)

2、 在新增頁面是,採取的是viewcontroller形式,而不是view

而不是:     [self.windows.view  addsubview: viewcontroller.view]

接下來就可以設定螢幕支援了,ios預設只支援豎屏,不支援轉屛

1、在viewcontroll.m 檔案中新增函式,表明支援旋轉螢幕

- (bool)shouldautorotate

這個函式的意思是,是否支援旋轉螢幕,yes ,支援

2、 新增函式,表明支援具體哪幾個螢幕

- (nsuinteger)supportedinte***ceorientations

return的就是支援螢幕的型別,在ios6之前,一般是返回uiinte***ceorientation 型別,上次左右,簡單明瞭

typedef ns_enum(nsinteger, uiinte***ceorientation) ;
但是ios6定義了新的型別uiinte***ceorientationmask,定義如下:

typedef ns_options(nsuinteger, uiinte***ceorientationmask) ;
這個型別,不僅包括上下左右,還包括他們的不同合集,比如左右,上下左右,上左右等,我在函式中的返回值 uiinte***ceorientationmaskall 就是指,所有的旋轉都支援

如此,旋轉的設定便定義好了。

那麼,如何準對旋轉,來執行相應的方法呢?

我們便需要用到

- (void)willrotatetointe***ceorientation:(uiinte***ceorientation)tointe***ceorientation duration:(nstimeinterval)duration
在函式裡,可以根據對應的uiinte***ceorientation 來應對,舉例如下:

- (void)willrotatetointe***ceorientation:(uiinte***ceorientation)tointe***ceorientation duration:(nstimeinterval)duration

if (tointe***ceorientation == uiinte***ceorientationportrait)

if (tointe***ceorientation == uiinte***ceorientationlandscaperight)

}

這個demo就是根據螢幕的旋轉來變換不同的色,很簡單,不解釋。

源**如下:螢幕旋轉源**

IOS螢幕旋轉

本部分 感謝原作者分享!螢幕旋轉學習筆記 加速計是整個ios螢幕旋轉的基礎,依賴加速計,裝置才可以判斷出當前的裝置方向,ios系統共定義了以下七種裝置方向 typedef ns enum nsinteger,uideviceorientation 以及如下四種介面方向 typedef ns enum...

iOS 螢幕旋轉

cpp view plain copy void willrotatetointe ceorientation uiinte ceorientation tointe ceorientation duration nstimeinterval duration else cpp view plain...

iOS螢幕旋轉

專案需求是在導航欄基類下保持豎屏,步驟如下 第一步如下圖,表示裝置只支援豎屏 第二步,通過繼承導航類建立乙個類,在該類裡面實現以下方法 bool shouldautorotate uiinte ceorientationmask supportedinte ceorientations 然後在導航子...