ios 7方向仅在1个viewController中响应

时间:2014-09-03 09:07:17

标签: ios objective-c

我取消选择负责方向的蓝色文件中的checkboxes, 因为我不希望我的应用程序响应方向更改,期望1个单视图控制器,是否有可能只使视图控制器响应方向?

我看过一些类似的问题,但是他们使用的是故事板,我不会使用它们...... 是否有任何编程解决方案?

viewController出现modaly

我以这种方式呼叫viewController

    youtubePlayerViewController * yt = [[youtubePlayerViewController alloc]initWithYoutubeId:@"5d3zDO14PD0"];
    [self presentViewController:yt animated:YES completion:nil];
在里面:

我已经尝试了很多东西,最终我试图强迫它回到横向,但它没有回应:(

但是,如果我允许蓝色文件中的复选框,它可以工作,但我的所有应用程序并不仅仅是以肖像方式运行: - /

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

2 个答案:

答案 0 :(得分:0)

为要支持多个方向的类子类UINavigationViewController并在ThatClass.m中添加

  // < iOS 6    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation    {
        return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
     }

   // > iOS6
   - (BOOL)shouldAutorotate {
      return NO;
     }

   // > iOS6
    - (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
    }

答案 1 :(得分:0)

1.如果rootView是UITabbarConroller。在TabbarController中添加此代码

 - (BOOL)shouldAutorotate
{
    return YES;
}

//only rotate in NeedRotateController
- (NSUInteger)supportedInterfaceOrientations
{
    UINavigationController * baseNavCtr = self.viewControllers[self.selectedIndex];
    if ([baseNavCtr.topViewController isKindOfClass:[NeedRotateController class]]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

2.如果rootView是UINavgationController

- (NSUInteger)supportedInterfaceOrientations
{
    if (self.topViewController isKindOfClass:[NeedRotateController class]) {
        return UIInterfaceOrientationPortraitUpsideDown;
    }else {
        return UIInterfaceOrientationPortrait;
    }
}

- (BOOL)shouldAutorotate {
    return YES;
}

3.如果这不起作用,请检查您的AppDelegate.m或info.plist是否支持旋转?