实际上,这里提到的删除和插入窗口视图的第一个视图的方法确实有效!
仅 iOS 纵向应用程序从 UIWebview youtube 以横向返回
我只需要出于某种原因不要在窗口子视图中要求第一个视图。我需要自己提供根视图。
所以我的解决方案是在支持两个方向的视图控制器中实现以下方法:
-(void)viewWillAppear:(BOOL)animated
{
m_b_avoid_landscape_orinetation = NO;
[super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
m_b_avoid_landscape_orinetation = YES;
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[[self getTabBar].view removeFromSuperview];
[window addSubview:[self getTabBar].view];
[super viewWillDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (m_b_avoid_landscape_orinetation)
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
else
return YES;
}
[self getTabBar] 提供了我的自定义标签栏,它作为窗口子视图中的第一个视图。
编辑因此,对于 iOS 6,它不再起作用了。我使用了插入和删除模态对话框的解决方案,如其他地方提到的新的supportedInterfaceOrientations 方法。
-(void)goBack
{
m_b_avoid_landscpae_orinetation = YES;
UIViewController *viewController = [[UIViewController alloc] init];
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window.rootViewController presentViewController:viewController animated:NO completion:^{
[viewController dismissModalViewControllerAnimated:NO];
}];
[self.navigationController popViewControllerAnimated:YES];
}
-(NSUInteger)supportedInterfaceOrientations
{
if (m_b_avoid_landscpae_orinetation)
return UIInterfaceOrientationMaskPortrait;
return UIInterfaceOrientationMaskAllButUpsideDown;
}