如何使用统一故事板(Xcode 6)在纵向模式下限制一个屏幕,在iPad中限制其他屏幕

时间:2014-12-31 08:43:04

标签: ios objective-c ios8 xcode6 ipa

我的应用仅在横向模式下运行,但我想在纵向模式下显示一个视图。所以我使用Unified storyboards(Xcode 6)创建了项目。我的项目只运行部署信息中的目标。

enter image description here

和我的视图控制器

enter image description here

我做错了什么?帮助我。

1 个答案:

答案 0 :(得分:0)

几周前我遇到了同样的问题。我创建了具有纵向方向的新UIViewController。后来我意识到改变方向是不够的,然后我使用下面的代码来改变方向。使用下面的代码来改变方向。

-(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;
    }
  }
}