2011-05-05 42 views
6

是否有可能(在運行時以編程方式)查詢導航欄和/或工具欄的高度/厚度將在旋轉後?在-shaouldAutorotateToInterfaceOrientation中預測UI元素框架:

也就是說,當爲特定的子視圖構建框架時,我想設置其框架相對於導航欄和工具欄之間的可用空間。爲了使其平滑,最好在shouldAutorotateToInterfaceOrientation:而不是didRotateFromInterfaceOrientation:中執行此操作,但是在方向設備之間的值不同,例如self.navigationController.toolbar.frame.size.height

我想計算反對什麼工具欄上的厚度我的新子視圖框架,我想這樣做沒有硬編碼值,如32點,44pt等

有什麼想法?

回答

1

你應該做你所有的幀大小調整在willAnimateRotationToInterfaceOrientation:duration:

AFAIK是沒有辦法預測你的UIViews的大小,直到你達到didRotateFromInterfaceOrientation:

一種方法可以做所有的幀代碼調整,包括工具欄。這樣你就可以完全控制UI元素的大小。

1

您可以在willAnimateRotationToInterfaceOrientation:duration:方法中更改您的視圖框架。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    NSLog(@"%@", NSStringFromCGRect(self.navigationController.navigationBar.frame)); 
} 

有關更多信息,請查看Apple提供的文檔。