簡體   English   中英

模態視圖控制器強制iOS 6中的橫向方向

[英]Modal View Controller force Landscape orientation in iOS 6

我有一個以縱向模式呈現的UITabBarController。 在其中一個選項卡上,我有一個按鈕,以模態方式顯示UIViewController(一個簡單的故事板segue執行操作)。

我希望這個模態視圖以橫向模式顯示,但我不能讓它自動轉動。

我在模態視圖控制器中有這個

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

我已將landscapeLeft添加到.plist支持的方向(雖然這也允許TabBar旋轉,我不想要)

我還將它添加到模態視圖的ViewDidLoad中

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;

但我不能讓它自己旋轉。

謝謝

編輯----

似乎應該是自動旋轉甚至沒有被調用!

此外,我正在嘗試檢測方向,下面的代碼總是顯示2,無論方向如何!

if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait) {
        NSLog(@"1");
        self.hostView.frame = CGRectMake(0, 60, 200, 255);
    } else {
        NSLog(@"2");
        self.hostView.frame = CGRectMake(0, 45, 480, 255);
    }

編輯2 ---

我的錯。 我想我應該提到我正在使用iOS 6.顯示器在iOS 5上自動旋轉。不推薦使用shouldAutorotateToInterfaceOrientation,因此我需要閱讀新方法。

iOS 6.0發行說明
“更多的責任轉移到應用程序和應用程序委托。現在,iOS容器(如UINavigationController)不會咨詢他們的孩子,以確定他們是否應該自動旋轉。”

-(BOOL)shouldAutorotate不應該從IOS6調用任何Container(如UINavigationController)下的UIViewController的Uutorotate。

嘗試使用Category將方法添加到現有UINavigationController類的解決方案。

shouldAutorotate方法中,您可以在self.viewControllers的每個視圖控制器中調用shouldAutorotate方法。 實際上,您可以傳遞給您的子視圖控制器。

如果要在iOS6中強制旋轉,rootviewController應該實現以下方法:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return YES;
}

在iOS 6中,似乎這種方法可能有助於強制iOS 6上的特定方向。

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

我仍然試圖讓它工作,並將更新任何調查結果。

我在我的應用程序中完成此操作,並通過shouldAutoRotateToInterfaceOrientation執行此操作,與您略有不同:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
  return (YES);
 return (NO);
}

對於iOS 6,您還必須設置window.rootViewController = {您的根視圖控制器}; 在你的應用程序委托中。 我希望這是你的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM