我的菜单仅为肖像和详细视图(使用UIWebView
)可以是纵向或横向。将视图从纵向更改为横向时,方向不会更改
当我进入详细视图和旋转设备的风景,并从那个屏幕回到那个只应该是肖像菜单,然后菜单是横向(与状态栏和导航栏)。
有没有办法避免这种情况,并强制屏幕旋转到所需的(支持)方向?
我的菜单仅为肖像和详细视图(使用UIWebView
)可以是纵向或横向。将视图从纵向更改为横向时,方向不会更改
当我进入详细视图和旋转设备的风景,并从那个屏幕回到那个只应该是肖像菜单,然后菜单是横向(与状态栏和导航栏)。
有没有办法避免这种情况,并强制屏幕旋转到所需的(支持)方向?
菜单的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
调用。
如下
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIViewController *controller = [[UIViewController alloc] init];
[self presentViewController:controller animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
}
setValue:forKey:方法很漂亮。但它也是一个私人API。这会导致我的申请被拒绝吗? (使用它的iOS 8) – Cutetare
@Cutetare我也很好奇。有没有人试过这个? –
我结束了对iOS8使用另一种方法,请参阅http://stackoverflow.com/questions/24907239/iphone-interface-orientation-on-ios8 – Cutetare