2014-06-10 92 views
2

我的菜單僅爲肖像和詳細視圖(使用UIWebView)可以是縱向或橫向。將視圖從縱向更改爲橫向時,方向不會更改

當我進入詳細視圖和旋轉設備的風景,並從那個屏幕回到那個只應該是肖像菜單,然後菜單是橫向(與狀態欄和導航欄)。

有沒有辦法避免這種情況,並強制屏幕旋轉到所需的(支持)方向?

回答

2

菜單的viewController的變化viewWillAppear提出@kkumpavat解決方案並沒有爲我工作或者還不夠清楚,我去了解它。我沒有更多的搜索和發現解決方案,它使用:

// http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation 
    // http://openradar.appspot.com/radar?id=697 
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") 
            withObject:UIInterfaceOrientationPortrait]; 

但這產生惱人的警告,我已經換它:

//force update of screen orientation 
if (self.interfaceOrientation != [self preferredInterfaceOrientationForPresentation]) { 
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: [self preferredInterfaceOrientationForPresentation]] 
           forKey:@"orientation"]; 
} 

從NavigationController的viewDidAppear調用。

+0

setValue:forKey:方法很漂亮。但它也是一個私人API。這會導致我的申請被拒絕嗎? (使用它的iOS 8) – Cutetare

+0

@Cutetare我也很好奇。有沒有人試過這個? –

+0

我結束了對iOS8使用另一種方法,請參閱http://stackoverflow.com/questions/24907239/iphone-interface-orientation-on-ios8 – Cutetare

-1

如下

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    UIViewController *controller = [[UIViewController alloc] init]; 
    [self presentViewController:controller animated:NO completion:nil]; 
    [self dismissViewControllerAnimated:NO completion:nil]; 
} 
+0

我應該在哪裏放?導航離開詳細視圖我有導航控制器欄中的後退按鈕。 –

+0

答覆已更新。這樣你不必做太多。 – kkumpavat

+0

:)你確定嗎?此更新後,我只能看到黑屏。 –

相關問題