1
我有2個視圖控制器,根和細節。根視圖控制器支持橫向和縱向,因此它具有以下代碼:pushViewController: - 當設備處於橫向模式時,如何以縱向模式顯示?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
上述代碼完美適用於根視圖控制器。
如果正在顯示根視圖控制器,並且用戶將設備旋轉到橫向模式,則視圖會相應地進行調整。從這一點來看,如果將我的詳細視圖控制器推到堆棧上,它將以橫向模式加載。但是,它不應該,因爲我已將它配置爲僅支持肖像模式。我使用下面的代碼在我的詳細視圖控制器:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
這只是結束了運行相同代碼的宏我已經有了。然而,只是爲了好玩,我試過了...而且我收到了相同的結果。我的第二個視圖加載在橫向模式下,而不是縱向... – bpatrick100 2011-02-16 17:17:19