簡體   English   中英

旋轉后獲取UIViewController視圖的大小

[英]Getting the size of a UIViewController's view after rotation

我有一個帶有一堆子視圖的UIViewController,如果iPad處於縱向或橫向模式,我需要以不同的順序布局。 我希望能夠在旋轉后獲取UIViewController視圖將要轉換為的大小,以便我可以為子視圖計算新的幀集。 但是,我沒有找到任何方法在旋轉發生之前獲得這個新的大小,並且當旋轉發生時,為時已晚,因為我無法動畫子視圖轉換到新的位置。

有沒有人知道這方面的方法?

你有沒有嘗試過willAnimateRotationToInterfaceOrientation:duration: . 正如文件所述:

調用此方法時,interfaceOrientation屬性已設置為新方向。 因此,您可以在此方法中執行視圖所需的任何其他布局。

我相信視圖控制器的視圖也應該在這個方法中有新的維度。

在標題中定義landscapeportrait視圖,將它們附加到“界面”構建器中,然后嘗試以下代碼:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
      (interfaceOrientation == UIInterfaceOrientationLandscapeRight))){

        self.view = landscape;

 }else if(((interfaceOrientation == UIInterfaceOrientationPortrait) || 
     (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){

        self.view = portrait;

    }
    return YES;
}

這比為視圖中的每個對象計算新幀要容易得多。

要設置動畫,你可以輸入[UIView beginAnimations:@"animation" context:nil]; [UIView commitAnimations]; 動畫到新視圖。

暫無
暫無

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

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