簡體   English   中英

iOS方向更改,但頁面仍然是垂直的

[英]iOS Orientation changing, but page is still vertical

因此,當設備方向發生變化時,我使用以下代碼加載UIView,但是當頁面加載時,頁面上的內容沒有以正確的方式布局。 有關如何改變這一點的任何想法?

旋轉而不在項目設置中左右檢查。 旋轉而不在項目設置中左右檢查。

在項目設置中左右檢查旋轉。 在項目設置中左右檢查旋轉。 - 我實際上傾向於這個,因為至少狀態欄位於正確的區域,但是失敗的是頁面的寬度沒有變化,允許我水平構建......

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];


- (void)deviceOrientationDidChange{
        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation == UIDeviceOrientationPortrait){
            NSLog(@"I'm portrait!");

        }
        else if (orientation == UIDeviceOrientationLandscapeLeft) {
            NSLog(@"I'm landscape LEFT!!");

        }
        else if (orientation == UIDeviceOrientationLandscapeRight) {
            NSLog(@"I'm landscape Right!!");

        }
        else {

        }
}

您是否在常規設置中選擇了所有方向?

在此輸入圖像描述

您的代碼正確響應設備方向的更改。

問題可能出在您創建視圖的方式上。
最簡單的方法是使用故事板或IB,並設置約束,因此在旋轉時,您的視圖適合其新界限。

通過在didGainWindow方法中對頁面進行一些更改,能夠使用下面的代碼解決問題。

- (void)changePagePostionSettings{
    self.w = 568;
    self.h = 320;
    customBackground.w = 568;
    customBackground.h = 320;  
}

暫無
暫無

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

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