我的菜单只有纵向,详细视图(UIWebView
)可以是纵向或横向。
当我输入详细视图并旋转设备横向并以此方式从该屏幕返回到仅应为纵向的菜单时,菜单处于横向(以及状态栏和导航栏)。
有没有办法避免这种情况并强制屏幕旋转到所需(支持)方向?
答案 0 :(得分:2)
@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
调用。
答案 1 :(得分:-1)
更改菜单viewController的viewWillAppear
,如下所示
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIViewController *controller = [[UIViewController alloc] init];
[self presentViewController:controller animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
}