2014-06-10 94 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

:)你确定吗?此更新后,我只能看到黑屏。 –

相关问题