利用Interface Builder開發(fā),我們可以快速的拖拽出合適的界面布局,但是屏幕自動切換布局不能很好的適配,下圖是,沒有做任何調(diào)整的狀態(tài)下,實現(xiàn)的橫豎屏切換,可以看到界面不是很美觀。有什么解決方案嗎???
2 回答

weibo_青梅竹馬醬_0
TA貢獻27條經(jīng)驗 獲得超64個贊
利用Interface Builder適配器自動適配調(diào)整界面。
選中控件,按command+3,上圖紅框部分的紅線表示距離不能自動適配,要是虛線表示距離可以自動適配。我們選擇可以自動適配,最后的結(jié)果就如上圖。

竹馬君
TA貢獻64條經(jīng)驗 獲得超115個贊
在橫豎屏切換時,每個控件重新布局。
首先創(chuàng)建兩個視圖:
IBOutlet?UIView?*hView; IBOutlet?UIView?*vView;
創(chuàng)建相應的@property方法.
然后在IB中在復制一個view。
把一個視圖做橫屏時的布局,一個view做豎屏時的布局。把相應的view和相應的方法相連接,在設置一個默認視圖為view。
下面就是代碼實現(xiàn):
-?(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation?{? ????????if?(interfaceOrientation==UIInterfaceOrientationLandscapeLeft)?{? ????????????//zuo? ????????????self.view=self.hView;? ???????????}? ????????if?(interfaceOrientation==UIInterfaceOrientationLandscapeRight)?{? ????????????//you? ????????????self.view=self.hView;? ??????????}? ????????if?(interfaceOrientation==UIInterfaceOrientationPortrait)?{? ????????????//shang? ????????????self.view=self.vView;? ???????????}? ????????if?(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)?{? ????????????//xia? ????????????self.view=self.vView;? ??????????}? ????????return?YES;? ????}
添加回答
舉報
0/150
提交
取消