如何實現ios螢幕的橫豎屏自適應

2021-06-28 18:38:13 字數 1185 閱讀 4373

首先在uiviewcontroller的

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

inte***ceorientation

方法中設定裝置要支援的deviceorientation;

在uiviewcontroller的

-(void)willrotatetointe***ceorientation(uiinte***ceorientation)

tointe***ceorientation

duration:(nstimeinterval)

duration

或者-(void)willanimaterotationtointe***ceorientation(uiinte***ceorientation)

inte***ceorientation

duration:(nstimeinterval)

duration

重新設定所有子view的frame

當uiview設定成自動適配螢幕(即myview.autoresizessubviews = yes)時,當我們重新設定myview的frame時(一般螢幕旋轉時我們都會重新設定view的frame),會自動呼叫layoutsubviers方法,我們可以在該方法中判斷螢幕的方向,並調整各子view的frame。

如果工層中有乙個superviewcontroller,然後在該控制器的試圖上加上了另乙個subviewcontroller的view,無論如何subviewcontroller的以上三個方法都不會被呼叫,這個時候,可以在superviewcontroller的

-(void)willrotatetointe***ceorientation(uiinte***ceorientation)

tointe***ceorientation

duration:(nstimeinterval)

duration

或者-(void)willanimaterotationtointe***ceorientation(uiinte***ceorientation)

inte***ceorientation

duration:(nstimeinterval)

duration

方法中重新配置subviewcontroller的view

ios 旋轉螢幕橫豎屏總結

第一種 通過人為的辦法改變view.transform的屬性。具體辦法 view.transform一般是view的旋轉,拉伸移動等屬性,類似view.layer.transform,區別在於 view.transform是二維的,也就是使用仿射的辦法通常就是帶有字首cgaffinetransfor...

iOS開發螢幕旋轉鎖定橫豎屏解決方法

第一步 配置為豎屏。禁用其他方向。如圖示 第二步 在viewdidload方法中用以下方法 說明 不是真正的旋轉螢幕,只旋轉當前的view self.view.transform cgaffinetransformmakerotation m pi 2 self.view.bounds cgrect...

iOS 橫豎屏的切換以及個別介面橫屏

進入正文前先認識幾個概念 portrait 豎屏 home鍵在下邊 upside down 豎屏 home鍵在上邊 landscape 橫屏 landscape left 橫屏home鍵在左邊 landscape right 橫屏home鍵在右邊 1 先讓視窗支援橫豎屏 兩種方法可以修改視窗對橫豎屏...