![](/img/trans.png)
[英]How to configure different layouts for Portrait and Landscape Orientations using Auto Layout?
[英]Different user interfaces for landscape and portrait orientations
長期以來,我一直沒有找到一個好的答案。
是否有可能(必須!;)構建不同的用戶界面,例如風景和肖像或具有3,5“ oder 4”顯示屏的iPhone。
就像在代碼中說的那樣,THIS是橫向界面,而THIS是縱向界面...
我希望有一個簡單的方法。 :)
由德國慕尼黑致以最誠摯的問候
勞倫茲
這就是我的方法。 我做了一個名為configureViewForOrientation:
的函數,該函數將要為其設置接口的方向作為參數。
-(void)configureViewForOrientation:(UIInterfaceOrientation)orientation
{
if (UIInterfaceOrientationIsPortrait(orientation))
{
//set up portrait interface
}
else
{
//set up landscape interface
}
}
您可以從viewDidLoad
(或最初設置界面的任何位置)中調用此方法,並使用[UIApplication sharedApplication].statusBarOrientation
將其提供給當前方向:
-(void)viewDidLoad
{
[super viewDidLoad];
[self configureViewForOrientation:[UIApplication sharedApplication].statusBarOrientation];
}
您還可以在旋轉設備時調用它:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self configureViewForOrientation:toInterfaceOrientation];
}
有幾點警告(例如您是否在應用啟動時立即檢查設備方向),但這在大多數情況下都有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.