2012-10-04 122 views
6

我想支持iOS 6旋轉。麻煩的是,我一直在瀏覽大量文檔和堆棧溢出問題,但還沒有發現任何深度解決方案。我只看到,我應該這兩種方法添加到我的視圖控制器類 - 但是,如果我沒有記錯的話,他們不會以同樣的方式操作作爲預iOS 6的方法:iOS 6旋轉:推視圖控制器

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; // use what is appropriate for you. 
} 

我應用程序目前使用以下代碼在iOS6之前旋轉。請注意,我使用界面方向參數來確定是否要推送視圖控制器。我如何在iOS 6旋轉代表中實現這一點?

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation; 

    if (self.tabBarController.view.subviews.count >= 2) 
    { 
     UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1]; 

     if(toOrientation != UIInterfaceOrientationLandscapeLeft && toOrientation != UIInterfaceOrientationLandscapeRight) 
     { 
      CUSTOM_DEBUG_LOG("\n\nRotated back to Portrait"); 
      tabBar.hidden = FALSE; 
     } 
    } 
} 

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     CUSTOM_DEBUG_LOG("\nView going landscape"); 
     ScrollViewController *s = [[ScrollViewController alloc] initWithNibName:@"ScrollViewController" bundle:nil]; 
     [self.navigationController pushViewController:s animated:NO]; 
     [s release]; 
     self.tabBarController.tabBar.hidden = YES; 
     self.navigationController.navigationBar.hidden = YES; 
    } 

} 
+1

觀看關於視圖控制器的WWDC 2012電影。 – matt

+0

我想我並沒有恰當地說出我的問題,因爲我的應用程序在這裏沒有任何答案。我基本上無法在iOS中獲得輪換工作,我認爲willAnimate ...函數也被棄用。原來,他們不是。所以我的應用程序仍然有效萬歲? 不幸的是,我在我的頁面上有巨大的不美觀的白色條紋,我需要擺脫它。時間發佈另一個問題。 –

回答

3

結帳thisthis SO討論。

[編輯]

是不是在iOS的6.0不贊成你提到的方法,他們將繼續工作。這只是Auto Rotation工作方式的改變。到目前爲止,視圖控制器負責決定它們是否旋轉,但現在RootViewController將決定它們的子節點是否應該旋轉。如果你沒有rootviewcontroller設置,那麼你必須將它添加到窗口,然後在rootviewcontroller中放置shouldAutoRotate和supportedInterfaceOrientations方法。

+0

如果我沒有弄錯,那看起來好像只是將代碼從我的willAnimate函數中移出到另一個函數中,看起來更好,但功能上沒有其他功能。 –

+0

對不起,我誤解了你的問題。編輯我的答案。 – applefreak

+0

我會接受!謝謝:) –

3

家長意見,現在處理在IOS 6子類的導航控制器旋轉,並添加一個布爾

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; // your rotation here 
} 
+0

我不確定我是否理解。你能給我一個示例代碼片段或向我展示如何處理推視圖控制器?你簡直就是把第一塊代碼粘貼回來了,而且這對我來說根本沒有幫助。 我應該提到我爲橫向模式推送單獨視圖控制器的原因是因爲橫向UI與縱向完全不同。 –

+1

您可能需要考慮重寫該代碼,以便在輪換時簡單地更改佈局。如果不同的用戶界面具有相同的組件,那就很簡單。如果有不同的組件,則可以適當地顯示/隱藏。如果你真的想保持獨立的視圖控制器,那麼它可能會最好,如果有一個父視圖控制器添加/刪除和/或顯示/隱藏適當的子視圖控制器在一個旋轉......這樣你就不會必須處理旋轉時推送/彈出視圖控制器的幕後功能。 – Matt

+0

推/低效率還是非常不理想的?該應用程序與iPhone的音樂應用程序非常相似,如果您在任何Tabbar的視圖控制器(是的,我的應用程序都有一個TabBar)上橫向傾斜,則會將其投影到隱藏流中。對於我的應用程序,您會被扔進我的橫向視圖控制器。它似乎適用於iOS 5和更低版本,但我試圖弄清楚iOS 6的情況。我還必須保持與舊版本iOS的兼容性。 –

1

當我第一次發佈問題時,我可能沒有正確實現iOS6旋轉代碼。

我錯誤地認爲willAnimateRotationToInterfaceOrientation函數在iOS6中被棄用,導致我相信有一個帶有方向參數的新的iOS旋轉委託。事實證明情況並非如此,所以我的應用程序的作品。

我插入我的應用程序的代碼只是這樣的:

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight); 
} 
+0

+1的「複製和粘貼」性。感覺不像查找定向蒙版合併語法... –

+2

便利值UIInterfaceOrientationMaskAllButUpsideDown更具可讀性。 – eclux

1

如果您正在使用一個UINavigationController,覆蓋shouldAutomaticallyForwardRotationMethods = YES財產。

然後像馬克S說,也覆蓋shouldAutorotatesupportedInterfaceOrientations爲兒童風險投資。

+0

不錯!接得好。我會給你一艘快艇(: –