我使用SplitView模板創建了我的iPad應用程序。 我不知道什麼是限制我的應用程序到橫向模式的最佳方式?如何限制我的應用程序爲橫向模式?
我試圖重寫shouldAutorotateToInterfaceOrientation:
方法在DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
但4.2 GM仍然馬車並未能顯示控制器視圖。我還有什麼其他選擇?
在此先感謝。
UPDATE1
我已經提交了一份bug報告: Bug ID #8620135
我的應用程序幾乎完成,我必須找到一個工作,以防萬一,因爲我不認爲他們在4.2正式發佈前(GM已經出來了!)
爲了重新創建bug,只需使用SplitView模板並覆蓋上面的代碼在任何UIViewControllers(RootViewController的或DetailViewControllers)的方法
UPDATE2
我已經發現一個變通。 (對於完整的作品,看到周圍UPDATE3)
設置UISupportedInterfaceOrientations只支持風景,這將迫使應用程序開始在橫向模式下允許DetailViewController正常啓動(因此正確顯示)
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
但如果您旋轉裝置,它原來人像模式!!!,所以仍然是必要的覆蓋shouldAutorotateToIntercafeOrientation
:如上
討論:
如果這不會是一個錯誤,我會期望警告或執行錯誤,異常或以視圖控制器不支持的方向啓動應用程序。此外,爲什麼只有DetailViewController不顯示?如果這是規範,那麼RootViewController也應該無法加載。你不覺得嗎? 感謝你幫...;)經過進一步的測試中,我已經意識到上述的變通不會在某些情況下工作
UPDATE3
。例如,當設備在橫向時啓動應用程序將無法正常工作! 真正的問題似乎是,在iOS4.2GM中,UISplitViewController需要所有控制器在其加載時都具有所有旋轉。所以有必要欺騙他,以便在橫向模式下加載,然後不允許他旋轉其視圖控制器。
所以這裏是這個令人討厭的iBug的新的解決方法。
第一步: 設置的Info.plist像這樣:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
第二步 在DetailViewController.m或.H(從SPLITVIEW模板)
BOOL lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//WORK-ARROUND: Bug ID# 8620135.
if (lockRotation) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}else{
return YES;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//set NO here since this is called before shouldAutorotateToInterfaceOrientation method is called
lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
}
- (void)viewDidAppear:(BOOL)animated {
//set YES as soon as possible, but after shouldAutorotateToInterfaceOrientation method was called
lockRotation = YES; //WORK-ARROUND: Bug ID# 8620135.
[super viewDidAppear:animated];
}
重要提示設置一個新的標誌: 請注意,此錯誤僅在加載UISplitViewController時出現,並且不會每次出現其視圖 。因此,要查看此錯誤,請確保應用程序之前已終止。
也許文件錯誤? ;) – 2010-11-02 14:14:42
這個問題說明你在DetailViewController中做了改變,是否正確的控制器重寫了方法? – 2010-11-02 14:46:18
我已經報告了錯誤 – nacho4d 2010-11-02 16:08:20