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

后端 未结 3 1338
無奈伤痛
無奈伤痛 2020-12-07 17:42

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

Confli

相关标签:
3条回答
  • 2020-12-07 18:01

    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.

    0 讨论(0)
  • 2020-12-07 18:02

    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.

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

    In you AppDelegate do the following

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

    }

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

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

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

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

    0 讨论(0)
  • 2020-12-07 18:20

    Try this tweak:

    #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000  
    - (NSUInteger)supportedInterfaceOrientations  
    #else  
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations  
    #endif  
    {
       return UIInterfaceOrientationMaskPortrait;
    }
    
    0 讨论(0)
提交回复
热议问题