Ios 以编程方式设置允许的方向

Ios 以编程方式设置允许的方向,ios,objective-c,xcode,ios7,ios8,Ios,Objective C,Xcode,Ios7,Ios8,嘿,我试着设置我允许的方向,但它不起作用 AppDelegate.m: - (NSUInteger)supportedInterfaceOrientations { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){ return UIInterfaceOrientationMaskAll; }else{ return UIInterfa

嘿,我试着设置我允许的方向,但它不起作用

AppDelegate.m:

- (NSUInteger)supportedInterfaceOrientations
    {
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
        return UIInterfaceOrientationMaskAll;
        }else{
        return UIInterfaceOrientationMaskPortrait;
        }

    }

在我的Info.plist中,我激活了所有方向。

如果你想让你的应用程序旋转,你需要在应用程序的每个视图控制器中设置旋转

可能有必要为您的UINavigationController或UITabBarController创建一个自定义类,以使所有内容按照您对此类代码的想法进行旋转:

@implementation CustomTabBarController

-(BOOL)shouldAutorotate
{
    if(self.viewControllers && self.selectedIndex<self.viewControllers.count)
        return ((UIViewController*)self.viewControllers[self.selectedIndex]).shouldAutorotate;
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if(self.viewControllers && self.selectedIndex<self.viewControllers.count)
        return ((UIViewController*)self.viewControllers[self.selectedIndex]).supportedInterfaceOrientations;
    return UIInterfaceOrientationMaskPortrait;
}

@end

使用这两个自定义类,您可以直接从ViewController本身处理应用程序是否应该旋转,因此这样做很方便。

I dpnt要旋转。我想设定允许的比例。是否可以在App delegate中说,我支持iOS8,而对整个App的旧版本支持Wich?您需要为应用程序的每个视图控制器设置允许的方向,或者使用继承仅定义一次,但要使其工作,必须在TabBar和navigationBar(如果可以省略)中定义它。
@implementation CustomNavigationController

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}

@end