2010-11-02 76 views
13

我使用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時出現,並且不會每次出現其視圖 。因此,要查看此錯誤,請確保應用程序之前已終止。

+1

也許文件錯誤? ;) – 2010-11-02 14:14:42

+0

這個問題說明你在DetailViewController中做了改變,是否正確的控制器重寫了方法? – 2010-11-02 14:46:18

+0

我已經報告了錯誤 – nacho4d 2010-11-02 16:08:20

回答

2

我問了一個500的賞金問題seems to be the same thing you're facing

從我有限的經驗來看,製作只有風景的iPhone應用程序要比僅有風景的iPad應用程序要容易得多。我不知道爲什麼有什麼不同,但蘋果說要採取的步驟,使其景觀,只有自己不工作。

+0

我想我已經在那個線程中發現了一個提示,下面是我所做的和它的工作,但這肯定是一個工作環節。我相信這不應該是必要的。看我的update2。 – nacho4d 2010-11-02 18:12:54

+0

即使強硬,我發現自己的答案...這個答案讓我想起它。所以謝謝;) – nacho4d 2010-11-03 06:17:15

0

看看這個iPhone app in landscape mode,如果你還沒有。我打算建議簡單地將UISupportedInterfaceOrientations添加到Info.plist並指定兩個橫向方向。但是,顯然,這是不夠的,根據引用問題的答案。

1

試試這個(它的工作原理):

-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation { 
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     return YES; 
    } 
    else 
    { 
     return NO; 
    } 
} 
+0

根據你想要的模式修改'if'條件。上面的代碼限制它右轉。將'if'檢查更改爲UIInterfaceOrientationLandscapeLeft以鎖定左側。對於這兩種景觀模式,如果(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) – Sid 2010-11-02 18:26:10

+0

沒有工作......這是足夠的時候不使用UISplitViewController我相信。 – nacho4d 2010-11-02 18:32:55

+0

'UIInterfaceOrientationIsLandscape(interfaceOrientation);'是Apple宏在短時間內完成您在答案中所說的內容。所以提問者已經完成了你所說的事情。 – 2010-11-02 18:36:14

0

我相信這是一個BUG,我面對這個問題也。這是一些與

UIInterfaceOrientationLandscapeLeft 

做要複製這樣的情況:使用UISplitViewController模板

2)編輯的info.plist

Supported interface orientations 
-Landscape (left home button) 
-Landscape (right home button) 

1)創建一個新的iPad項目)DetailViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// return YES; 
NSLog(@"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft); 
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft; 
} 

4)運行它....你會看到一個空白的黑色視圖。不管你怎麼轉。 「UIInterfaceOrientationLandscapeLeft」從未檢測到。

順便說一下,nacho4d的添加BOOL檢查解決方法正在工作。大拇指:)

相關問題