在'supportedInterfaceOrientations'的实现中冲突返回types: – 警告

升级到Xcode 7.0后,我在UIViewControllerRotation方法中得到一个警告: - (NSUInteger)supportedInterfaceOrientations

在'supportedInterfaceOrientations'的实现中有冲突的返回types:'UIInterfaceOrientationMask'(aka'enum UIInterfaceOrientationMask')vs'NSUInteger'(aka'unsigned int')

为什么是这样的,我该如何解决?

编辑:如果你去定义,你会看到返回typesacctually已经改变: - (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0); 但在代码中更改返回types不会使警告消失。

试试这个调整:

 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 - (NSUInteger)supportedInterfaceOrientations #else - (UIInterfaceOrientationMask)supportedInterfaceOrientations #endif { return UIInterfaceOrientationMaskPortrait; } 

我正在使用这一个:

 #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0 #define supportedInterfaceOrientationsReturnType NSUInteger #else #define supportedInterfaceOrientationsReturnType UIInterfaceOrientationMask #endif - (supportedInterfaceOrientationsReturnType)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 

…比Nishant的修复稍长一些,但我认为更清楚一点。

我已经在这几个周末找出正确的解决scheme,我尝试了很多其他的解决scheme,但只是没有正常工作。 如果你只想要特定的UI在横向或纵向尝试下面的这个方法。 我正在运行Xcode 7.2.1,我正在使用Bool设置值与每个类中的NSUSerDefaults我想要遵循特定的UIInterfaceOrientations。下面的方法被调用每次有一个新的用户界面提出或设备旋转时,你可以通过把一个NSLog检查该方法中的bool的值来检查它,并亲自看看它是如何改变的。

 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow: 

在你AppDelegate执行以下操作

.h @property(assign,nonatomic)BOOL shouldRotate;

.M

 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED{ _shouldRotate = [[NSUserDefaults standardUserDefaults]boolForKey:@"rotateKey"]; NSLog(@"Did I get to InterfaceOrientation \n And the Bool is %d",_shouldRotate); if (self.shouldRotate == YES) return UIInterfaceOrientationMaskAllButUpsideDown; else return UIInterfaceOrientationMaskPortrait; 

}

现在在每一个类别,你想要有一个特定的UIINTERFACEORIENTATION做到这一点

  -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:YES]; // [[AppDelegate sharedAppDel]setShouldRotate:YES]; BOOL rotate = NO; [[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"]; [[NSUserDefaults standardUserDefaults]synchronize]; } -(BOOL)shouldAutorotate { return YES; } 

在要旋转的视图中,将布尔值更改为是。 现在在你的AppDelegate

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. BOOL rotate = NO; [[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"]; [[NSUserDefaults standardUserDefaults]synchronize]; return YES; } 

也在你的AppDelegate

 - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. BOOL rotate = NO; [[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"]; [[NSUserDefaults standardUserDefaults]synchronize]; } 

希望这有助于许多开发者。 经过多次testing和testing。

问候

JZ