簡體   English   中英

iPhone方向更改框架

[英]iPhone Orientation change frame of view

我想根據方向以編程方式設置UILable的位置。 但是當我回到Portrait時,它不起作用。

這是我的代碼:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)
    {
        lblUserName.frame = CGRectMake(20, 200, 280, 44); 
        lblPassword.frame = CGRectMake(20, 246, 280, 44); 
    }

    else
    {
        lblUserName.frame = CGRectMake(20, 220, 280, 44); 
        lblPassword.frame = CGRectMake(20, 266, 280, 44); 
    }
}

有兩種可能。您可以通過編程方式設置標簽。並在-(BOOL)應該AutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {}中檢查方向的條件

方法。否則,您可以使用自動調整大小蒙版。

嘗試使用以下IF條件:

 if ( UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
 { 

 } 
 else {}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//write code here
return YES;
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
//write code here
}

旋轉設備時,可使用這兩種方法設置標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM