ipad橫豎屏切換解決方案

2021-06-09 11:58:20 字數 1228 閱讀 7351

由於ipad的橫豎屏不同,所以好的應用,橫豎屏的頁面布局也不一樣。那麼就需要橫豎屏的整體解決方案。先看乙個橫豎屏布局不一樣的介面。

橫豎版顯示的內容相同,但是介面布局不同。要實現上述布局,主要是運用uiview中layoutsubviews方法。當uiview設定為自動適配螢幕時,當使用者旋轉裝置的時候,會呼叫layoutsubviews方法,我們只需重寫這個方法,然後判斷使用者螢幕的方向。在調整每個空間的位置即可。

下面是實現上述介面的最簡單的原型:

首先分析可以知道左面是,右面是乙個加文字的檢視。下面就實現乙個左面檢視右面是乙個圖加一段字的事例。

事例的截圖如下:

其中右面的文字和綠色部分是用乙個子檢視封裝的。

整個布局是我在主檢視中新增了乙個contentview檢視,在contentview檢視中新增了乙個articleview檢視。

其中articleview和contentview的xib檔案都開啟了

在contentview中重寫layoutsubviews方法,然後根據stausbar的方向判斷當前檢視的橫豎屏。具體**:

-(void)layoutsubviewselse if (inte***ceorientation==uideviceorientationlandscapeleft || inte***ceorientation == uideviceorientationlandscaperight)

} -(void)setverticalframe

-(void)sethorizontalframe

在具體的橫豎屏方法中,從新設定各個元件的座標即可。

接下來在contentview中新增articleview檢視。

-(id)initwithcoder:(nscoder *)adecoder

return self;

}由於我用的是xib,所以初始化方法為initwithcoder,在這個中新增新的檢視。

同樣在articleview中設定橫豎屏相應空間的座標即可。

-(void)layoutsubviewselse if (inte***ceorientation==uideviceorientationlandscapeleft || inte***ceorientation == uideviceorientationlandscaperight)

} -(void)setverticalframe

-(void)sethorizontalframe

源**:

android 橫豎屏切換問題的解決方案

只豎屏顯示的話 android screenorientation portrait 只橫屏顯示的話 android screenorientation landscape 畫面重新載入問題 在預設情況下橫豎 切換時會重新載入畫面,導致一些不必要的資源浪費,更嚴重的是畫面上保持的資料 特別是遊戲方面...

ios橫豎屏解決方案

ios生成pdf,並且以郵件的方式傳送出去 利用itouch看pdf word powerpoint文件 ios橫豎屏的效果是不相同的,其效果也是不一樣的。所以我們在開發中如果允許螢幕橫豎屏間的切換,那麼我們就要調整檢視的布局。利用inte ce builder開發,我們可以快速的拖拽出合適的介面布...

android 橫豎屏切換

private onclicklistener onclick new onclicklistener else 監聽系統設定的更改 override public void onconfigurationchanged configuration newconfig 在4.0以後需要加上scree...