2

我有一個UISplitViewController設置在我的應用程序的rootView。當viewDidLoad叫我左視圖控制器我做了檢查,然後使用提出一個模式視圖控制器以下:從UISplitViewController提供的modalViewController出現錯誤的方向

SiteConfiguration *config = [[SiteConfiguration alloc] initWithStyle:UITableViewStyleGrouped]; 
config.firstLoad = YES; 
UINavigationController *configNav = [[UINavigationController alloc] initWithRootViewController:config]; 
if ([Utility isIpad]) { 
    configNav.modalPresentationStyle = UIModalPresentationFormSheet; 
    configNav.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [[AppDelegate instance].splitViewController presentModalViewController:configNav animated:YES]; 
} else { 
    [self presentModalViewController:configNav animated:YES]; 
} 

如果iPad在橫向模式下,同時應用程序加載時,modalView顯示有不正確定位:

enter image description here

我可以旋轉iPad來解決這個問題,但爲什麼它加載錯了嗎?我的shouldAutorotateToInterfaceOrientation:在我的SiteConfiguration viewController中返回YES。什麼可能導致這個?

回答

3

小心你選擇展示模態控制器的地方。 我已經同一些自定義模式控制器的經驗和

- (void)viewDidLoad:(BOOL)animated

設置模態控制器(和它的陰影!)的方向並不總是像預期的那樣。

把你的代碼(presentModalViewController:configNav animated:YES)在

- (void)viewDidAppear:(BOOL)animated

代替。 (對於任何設置子視圖框架的代碼或對圖層進行任何操作(例如陰影圖層和陰影屬性)都可以這樣做)。

據我所知,旋轉視圖的子視圖旋轉可能不明顯,直到

- (void)viewDidLoad:(BOOL)animated
由於線程問題(一個線程可能開始繪製您的子視圖或模式控制器的視圖之前,旋轉傳遞到子視圖(和模態控制器)由主線程)。有人比我有更多的線程經驗可能能夠讓我們更清楚地瞭解這一點。

+0

我不得不把它放在'viewDidAppear:'中,並且做到了! – 2012-07-19 20:42:09

+0

哎呀,我打算輸入'viewDidAppear:'。我已經適當地編輯了我的答案 – 2012-07-19 20:44:33

0

shouldAutorotateToInterfaceOrientation:實際上並沒有旋轉界面,應用程序在收到UIDeviceOrientationDidChangeNotification通知後會這樣做。

嘗試在-(void) viewDidAppear:(BOOL)animated方法中添加設備方向檢查。

要強制旋轉界面,請使用以下代碼片段。

UIDeviceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation]; 
[UIApplication sharedApplication].statusBarOrientation = toInterfaceOrientation; 
相關問題