升级到Xcode 7.0后,我在UIViewControllerRotation方法中收到警告:- (NSUInteger)supportedInterfaceOrientations
:
执行中的冲突返回类型 'supportedInterfaceOrientations':'UIInterfaceOrientationMask'(又名 'enum UIInterfaceOrientationMask')vs'NSUInteger'(又名'unsigned INT')
为什么会这样,我该如何解决?
修改
如果你转到定义,你会看到返回类型实际上已经改变:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
但是更改代码中的返回类型并不会使警告静音。
答案 0 :(得分:113)
试试这个调整:
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
return UIInterfaceOrientationMaskPortrait;
}
答案 1 :(得分:10)
我正在使用这个:
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
#define supportedInterfaceOrientationsReturnType NSUInteger
#else
#define supportedInterfaceOrientationsReturnType UIInterfaceOrientationMask
#endif
- (supportedInterfaceOrientationsReturnType)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
......比Nishant的修复时间稍微长一些,但我认为有点清晰。
答案 2 :(得分:-1)
我已经在这几个周末找到了正确的解决方案,我已经尝试了许多其他解决方案,但只是没有正常工作。如果您只希望某些UI处于横向或纵向,请尝试以下方法。我正在运行Xcode 7.2.1,我使用Bool在每个我想要遵循特定UIInterfaceOrientations的类中设置值和NSUSerDefaults。每次出现新UI或设备旋转时,都会调用下面的方法,你可以通过让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;
}
在要旋转的视图中,将Bool值更改为是。 现在在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];
}
希望这有助于许多开发人员。 经过多次测试和测试。
此致
JZ