2

I am working on an App which is written in Objective-C. I have more screens and all screens are Landscape Left and Landscape Right orientations and these screens must not be in portrait mode. But I have got 3 different screens which should be in only Portrait mode must not be in Landscape Left or Landscape Right.

This is the code for Landscape mode for all screens-

This is the code for Landscape mode for all screens

And this is for Portrait mode for my app

Portrait mode

These are all I did in my View Controllers and In app Plist I have added needed orientations like This Info.plist

Plist info

And the app device orientation will automatically changes. like this - Device orientation.

I am pretty sure all is clear and should work as it is expected but for some reason when I use the app and lock the auto rotation and run the app it is automatically opening in Portrait mode and when I unlock the autorotation it will be in Landscape and you rotate it will be rotated to Portrait mode. I used shouldAutorate return YES because it should rotate it automatically between Landscape Left and Landscape Right so I used it also the portrait mode screen is opening in Portrait but it is autorotating when user rotates the device.

Any help would be appreciated, Please share any idea why my app is not working as expected.

Rashed
  • 2,349
  • 11
  • 26
  • I would suggest you architecture your application container classes correctly and exploit it instead of going through out your application and specifying rotation informations to each and every viewController. See this [post](https://stackoverflow.com/questions/29530495/supporting-universal-app-with-portrait-orientation-on-iphone-and-landscapeportr/31065938#31065938). Hope it gives you idea. – Athul George Mar 06 '18 at 05:19

1 Answers1

0

Following are the steps to fix this issue:

  1. Remove orientations from plist because it overrides whatever logic you have in your view controller.

  2. Keep below code where you have landscape orientations:

    -(BOOL)shouldAutorotate {
        return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    
  3. For portrait mode use it as below:

    -(BOOL)shouldAutorotate {
        return YES;
    }
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    } 
    

Now try locking the orientation your first view controller will appear in landscape and other one will be portrait regardless of orientation lock.

Yasir Ayaz
  • 91
  • 1
  • 5
  • I tried this way also but it is still same as it was. And I changed shouldAutorotate returns NO nothing changes same result. What do you think what else may cause to this problem by the way thanks for your answer. – Bekzod Rakhmatov Mar 06 '18 at 05:09
  • Please make sure to remove orientations from your plist and return Yes from shouldAutoRotate. – Yasir Ayaz Mar 06 '18 at 05:12
  • Also deselect all orientations in deployment info section as well. – Yasir Ayaz Mar 06 '18 at 05:14
  • Depending on what I check in Info it is showing up in plist automatically I remove from plist and it automatically removed from deployment info. – Bekzod Rakhmatov Mar 06 '18 at 05:21
  • Check this test project and you will get the idea of how it works: https://www.dropbox.com/sh/gmej63de21smxsf/AAB2ziw47VrVe2_14j1uEop1a?dl=0 – Yasir Ayaz Mar 06 '18 at 05:26
  • I created a new project in this new project all is working fine. I think in my project there is something wrong. Do you know what else may cause not to work orientation implementations. Thanks. – Bekzod Rakhmatov Mar 06 '18 at 08:10
  • Search in whole project and delete all the code related to orientation then do it step by step, May be you are doing some orientation related things in base class of your view controller.. – Yasir Ayaz Mar 06 '18 at 08:19
  • I deleted all implementation for orientation and I tried for only one view controllers some are working perfectly some not. I have a BaseViewController and in baseView controller I deleted all the implementation but it still not working. I could not solve this problem for like a month if you can. Can I contact you? – Bekzod Rakhmatov Mar 06 '18 at 12:45
  • Sure you can contact me – Yasir Ayaz Mar 06 '18 at 15:44
  • How can I contact you do you have any social media account? – Bekzod Rakhmatov Mar 06 '18 at 17:41