首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用统一故事板在iPad中将一个屏幕限制为纵向模式,而将其他屏幕限制为横向模式(Xcode6)

如何使用统一故事板在iPad中将一个屏幕限制为纵向模式,而将其他屏幕限制为横向模式(Xcode6)
EN

Stack Overflow用户
提问于 2014-12-31 16:43:04
回答 1查看 462关注 0票数 0

我的应用程序只在横向模式下运行,但我想在纵向模式下显示一个视图。因此,我使用统一故事板(Xcode6)创建了项目。我的项目仅在Deployment Info中运行。

和我的视图控制器

我做错了什么?帮帮我。

EN

Stack Overflow用户

发布于 2014-12-31 17:09:33

几周前我也遇到过同样的问题。我创建了一个带有纵向的新UIViewController。后来我意识到仅更改方向是不够的,于是我使用下面的代码来更改orientation.Use更改方向。

代码语言:javascript
运行
复制
-(void)viewWillAppear:(BOOL)animated
    {
      [self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:.2];
      [self awakeFromNib];

    }
    -(void)viewWillDisappear:(BOOL)animated {

      [[NSNotificationCenter defaultCenter] removeObserver:self                                                                                      name:UIDeviceOrientationDidChangeNotification
                                                    object:nil];
    }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
      if(is_iPad)
      {
        return YES;
      }else
      {
        return (UIInterfaceOrientationIsPortrait(toInterfaceOrientation));
      }
    }


- (void)awakeFromNib

{
  AppDelegate  *delegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
  delegate->isShowingLandscapeView=NO;

  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

  [[NSNotificationCenter defaultCenter] addObserver:self

                                           selector:@selector(orientationChanged:)

                                               name:UIDeviceOrientationDidChangeNotification

                                             object:nil];

}

- (void)orientationChanged:(NSNotification *)notification
{
  if (is_iPad) {
    AppDelegate  *delegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        !delegate->isShowingLandscapeView)
    {
      yourPotraitViewController *ypvc =[[yourPotraitViewController alloc] initWithNibName:@"yourPotraitViewController" bundle:nil];


      [self.navigationController pushViewController:objHomeLandscape animated:YES];
      delegate->isShowingLandscapeView=YES;
      // isShowingLandscapeView = YES;
    }
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
             delegate->isShowingLandscapeView)
    {
      [self.navigationController popViewControllerAnimated:YES];
      delegate->isShowingLandscapeView=NO;
    }
  }
}
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27718484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档