ios 'supportedInterfaceOrientations' 实现中的返回类型冲突: - 警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32699286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:46:04  来源:igfitidea点击:

Conflicting return type in implementation of 'supportedInterfaceOrientations': - Warning

iosobjective-cxcode

提问by turingtested

After upgrading to Xcode 7.0 I get a warning in the UIViewControllerRotation method: - (NSUInteger)supportedInterfaceOrientations:

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

Conflicting return type in implementation of 'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned int')

'supportedInterfaceOrientations' 实现中的返回类型冲突:'UIInterfaceOrientationMask'(又名 'enum UIInterfaceOrientationMask') vs 'NSUInteger'(又名 'unsigned int')

Why is that, and how do I fix it?

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

EDIT:If you go to the definition you'll see that the return type acctually has changed: - (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);but changing the return type in the code doesn't silence the warning.

编辑:如果您转到定义,您会看到返回类型实际上已更改: - (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);但更改代码中的返回类型并不能消除警告。

回答by Nishant

Try this tweak:

试试这个调整:

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

回答by turingtested

I am using this one:

我正在使用这个:

#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
#define supportedInterfaceOrientationsReturnType NSUInteger
#else
#define supportedInterfaceOrientationsReturnType UIInterfaceOrientationMask
#endif

- (supportedInterfaceOrientationsReturnType)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

... a little bit longer than Nishant's fix but a little bit clearer, I think.

... 比 Nishant 的修复要长一点,但我认为更清晰一点。

回答by John Z

I have been at this for a few weekends to figure out the proper solution, I have tried many others solutions but just did not work properly. If you want only certain UI to be in landscape or Portrait try this method below. I am running Xcode 7.2.1 , I am using a Bool to set the value along with NSUSerDefaults in each Class I want to follow specific UIInterfaceOrientations.The method below gets called each time there is a new UI presented or when the device is rotated , you could check this by putting a NSLog checking the value of the bool in that method and see for yourself how it changes.

我已经在这几个周末找出正确的解决方案,我尝试了许多其他解决方案,但都无法正常工作。如果您只希望某些 UI 处于横向或纵向,请尝试以下此方法。我正在运行 Xcode 7.2.1,我使用 Bool 在每个类中设置值以及 NSUSerDefaults 我想遵循特定的 UIInterfaceOrientations。每次出现新的 UI 或设备旋转时,都会调用下面的方法,您可以通过在该方法中放置一个 NSLog 检查 bool 的值来检查这一点,并亲眼看看它是如何变化的。

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

In you AppDelegate do the following

在您的 AppDelegate 中执行以下操作

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

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

.m

.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;

}

}

NOW IN EVERY CLASS YOU WANT TO HAVE A SPECIFIC UIINTERFACEORIENTATION DO THIS

现在,在每个课程中,您都希望拥有特定的 UIInterFACEORENTATION 执行此操作

 -(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;
}

In the Views you want to rotate change the Bool value to Yes. Now in your AppDelegate

在要旋转的视图中,将布尔值更改为是。现在在您的 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;
}

Also in your AppDelegate

同样在您的 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]; 
}

Hope this helps many developers. Tested and Tested many times.

希望这可以帮助许多开发人员。经过多次测试和测试。

Regards

问候

JZ

江泽民