iOS開發 戲說旋屏

2021-06-19 18:58:31 字數 1466 閱讀 9350

**:

橫豎屏切換,檢視亂了怎麼辦?

首先,我們必須了解一下下列4種狀態,它們被用來描述裝置旋轉方向:

uiinte***ceorientationlandscapeleft

向左,即home鍵在右

uiinte***ceorientationlandscaperight

向右,即home鍵在左

uiinte***ceorientationportrait

正立,即home鍵在下

uiinte***ceorientationportraitupsidedown

倒立,即home鍵在上

對於旋屏的處理,大致分為如下幾種情況和思路:

也許,你不需要旋屏支援,而希望鎖定螢幕

-(bool)shouldautorotatetointe***ceorientation:(uiinte***ceorientation)inte***ceorientation

也許,你需要支援旋屏,或者支援部分方向的旋屏

-(bool)shouldautorotatetointe***ceorientation:(uiinte***ceorientation)inte***ceorientation
也許,你的view有張背景圖,旋屏時系統幫助你拉伸了,但是卻沒有管你的其它部件,比如button,你希望直接改變button的大小和位置

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

if (uiinte***ceorientationislandscape(tointe***ceorientation))

}

也許,你並不希望用絕對座標去約束控制項,而是希望讓它通過旋**己適應螢幕的旋轉

- (void)viewdidload

- (bool)shouldautorotatetointe***ceorientation:(uiinte***ceorientation)inte***ceorientation

-(void)rotation_btn:(float)n

-(void)orientationchanged

}

也許,你需要autoresizessubviews = yes

也許,你希望橫豎屏有不同的布局效果,需要準備2份subview,在不同狀態去替換

當然不要忘記,需要調節設定圖示中的1、2處

來幫助我們完成自己想要的適應效果。example 動畫呈現的很清晰,^_^ 我就不再囉嗦了。

iOS開發 戲說旋屏

橫豎屏切換,檢視亂了怎麼辦?首先,我們必須了解一下下列4種狀態,它們被用來描述裝置旋轉方向 uiinte ceorientationlandscapeleft 向左,即home鍵在右 uiinte ceorientationlandscaperight 向右,即home鍵在左 uiinte ceor...

iOS旋屏控制

自己在網上搜相關的資料時,看到很多地方說去控制 shouldautorotatetointe ceorientation 這個方法。然而這個方法在ios5以後就沒有用了。對於旋屏現在主要是這兩個方法 當前ios8 bool shouldautorotate nsuinteger supportedi...

ios的旋屏控制技巧

在ios5.1 和 之前的版本中,我們通常利用shouldautorotatetointe ceorientation 來單獨控制某個uiviewcontroller的旋屏方向支援,比如 bool shouldautorotatetointe ceorientation uiinte ceorien...