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

和我的视图控制器

我做错了什么?帮帮我。
发布于 2014-12-31 17:09:33
几周前我也遇到过同样的问题。我创建了一个带有纵向的新UIViewController。后来我意识到仅更改方向是不够的,于是我使用下面的代码来更改orientation.Use更改方向。
-(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;
    }
  }
}https://stackoverflow.com/questions/27718484
复制相似问题