我有一個UIViewController,有一堆子視圖,如果iPad處於縱向或橫向模式,我需要按不同順序進行佈局。我希望能夠在旋轉後抓住UIViewController視圖將要轉換的大小,以便我可以爲我的子視圖計算新的一組幀。然而,在旋轉發生之前,我還沒有找到任何方法來獲得這個新的尺寸,到旋轉發生的時候已經太遲了,因爲我無法將子視圖轉換到新的位置。在旋轉後獲取UIViewController視圖的大小
有沒有人知道解決這個問題的方法?
我有一個UIViewController,有一堆子視圖,如果iPad處於縱向或橫向模式,我需要按不同順序進行佈局。我希望能夠在旋轉後抓住UIViewController視圖將要轉換的大小,以便我可以爲我的子視圖計算新的一組幀。然而,在旋轉發生之前,我還沒有找到任何方法來獲得這個新的尺寸,到旋轉發生的時候已經太遲了,因爲我無法將子視圖轉換到新的位置。在旋轉後獲取UIViewController視圖的大小
有沒有人知道解決這個問題的方法?
你試過willAnimateRotationToInterfaceOrientation:duration:
。正如文檔所述:
在調用此方法時,interfaceOrientation屬性已設置爲新方向。因此,您可以在此方法中執行視圖所需的任何其他佈局。
我相信視圖控制器的視圖也應該在這個方法中有其新的尺寸。
定義你的landscape
和portrait
意見在你的頭,在Interface Builder重視他們,試試這個代碼:
-(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];
爲新視圖設置動畫。
我目前正試圖找出這個相同的問題,我發現該視圖還沒有它的新維度。如果我在'willAnimateRotationToInterfaceOrientation:duration'中設置視圖的寬度,那麼視圖最終會在狀態欄上留下空隙。 – Aaron 2013-05-28 21:03:20