'supportedInterfaceOrientations' 的实现中存在冲突的 return 类型:- 警告
Conflicting return type in implementation of 'supportedInterfaceOrientations': - Warning
升级到 Xcode 7.0 后,我在 UIViewControllerRotation 方法中收到警告:- (NSUInteger)supportedInterfaceOrientations
:
Conflicting return type in implementation of
'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka
'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned
int')
这是为什么,我该如何解决?
编辑:
如果你去定义你会看到 return 类型实际上已经改变了:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
但更改代码中的 return 类型不会消除警告。
试试这个调整:
#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 的修复时间长一点,但更清晰一点。
我已经花了几个周末的时间来找出合适的解决方案,我已经尝试了很多其他的解决方案,但都没有正常工作。如果您只希望某些 UI 处于横向或纵向,请尝试以下方法。我是 运行 Xcode 7.2.1 ,我正在使用 Bool 来设置每个 Class 中的值以及 NSUSerDefaults 我想遵循下面的特定 UIInterfaceOrientations.The 方法被调用每个当出现新的 UI 或设备旋转时,您可以通过在该方法中放置一个 NSLog 检查 bool 的值来检查这一点,并亲眼看看它是如何变化的。
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:
在您的 AppDelegate 中执行以下操作
.h @属性(赋值,非原子)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;
}
现在每个CLASS你想要一个特定的UI界面定向
-(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];
}
希望这对许多开发人员有所帮助。
经过多次测试。
此致
JZ
升级到 Xcode 7.0 后,我在 UIViewControllerRotation 方法中收到警告:- (NSUInteger)supportedInterfaceOrientations
:
Conflicting return type in implementation of 'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned int')
这是为什么,我该如何解决?
编辑:
如果你去定义你会看到 return 类型实际上已经改变了:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
但更改代码中的 return 类型不会消除警告。
试试这个调整:
#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 的修复时间长一点,但更清晰一点。
我已经花了几个周末的时间来找出合适的解决方案,我已经尝试了很多其他的解决方案,但都没有正常工作。如果您只希望某些 UI 处于横向或纵向,请尝试以下方法。我是 运行 Xcode 7.2.1 ,我正在使用 Bool 来设置每个 Class 中的值以及 NSUSerDefaults 我想遵循下面的特定 UIInterfaceOrientations.The 方法被调用每个当出现新的 UI 或设备旋转时,您可以通过在该方法中放置一个 NSLog 检查 bool 的值来检查这一点,并亲眼看看它是如何变化的。
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:
在您的 AppDelegate 中执行以下操作
.h @属性(赋值,非原子)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;
}
现在每个CLASS你想要一个特定的UI界面定向
-(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];
}
希望这对许多开发人员有所帮助。 经过多次测试。
此致
JZ