【问题标题】:iOS Rotate View Only One View Controller's ViewiOS Rotate View Only One View Controller 的 View
【发布时间】:2012-08-18 18:28:32
【问题描述】:

我在一个项目中有两个视图控制器。但是,我希望其中一个视图控制器自动旋转,而另一个不自动旋转。

如果我如下所示设置主项目设置:

然后,所有视图控制器都会自动旋转,无论视图控制器中的以下代码如何,我都不想自动旋转:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        return YES;
    }
    return NO;
}

但是,如果我如下所示设置主项目设置,我不想自动旋转的视图控制器不会,但这也意味着我想要的视图控制器也不能。

我必须如何将主项目(plist 文件)设置与视图控制器的设置集成,以便一个视图控制器自动旋转而另一个不会?

【问题讨论】:

  • 看看这个answer
  • 你们两个ViewController的关系怎么样?例如。推送关系或模态关系hp。

标签: iphone objective-c ios autorotate


【解决方案1】:
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在 iOS 6 中已贬值,因此如果您的项目正在运行,那就是它无法运行的原因。你需要做的是实现:

- (NSUInteger)supportedInterfaceOrientations
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

第一个将告诉控制器允许使用哪个方向,第二个将告诉它首先使用哪个方向。请注意,仅当方法 shouldAutorotate: 返回 YES 时才会调用第一个方法。

这些是可用于supportedInterfaceOrientations 的常量:

UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown

请注意,这些仅适用于 iOS 6.0。

【讨论】:

    【解决方案2】:

    假设我正在使用 tabbarController & iOS

    //In First View Controller
    
    //BOOL activeStatus;
    
    -(void)viewWillAppear:(BOOL)animated
    {
     activeStatus=YES;
    }
    
    
    -(void)viewWillDisappear:(BOOL)animated
    {
     activeStatus=NO;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) && activeStatus==YES)
    {
        return YES;
    }
    
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    

    //In Second View Controller
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    
     return YES;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 2021-02-18
      • 2019-06-15
      相关资源
      最近更新 更多