Do “Supported Interface Orientations” have precedent?

久未见 提交于 2019-12-12 02:59:46

问题


I'm developing an app and I would like one screen to auto-rotate to landscape.

This will be the only rotating screen in the app.

I'm trying to find the easiest way of doing this.

If I set the supported orientations in the build summary page (i.e. with the toggle buttons) so that it is just portrait. Can I then override this in the code for the screen I want to auto-rotate?

Or do I have to do it the other way round? i.e. support all orientations and then disable for all the screens I don't want to rotate?

Thanks


回答1:


Or do I have to do it the other way round? i.e. support all orientations and then disable for all the screens I don't want to rotate?

Yes. You must list for the Info.plist all the orientations you will support. Then limit particular view controller orientations with supportedInterfaceOrientations. Your one landscape view controller must be presented, i.e. use a "modal" segue or call presentViewController:animated:.

My answer here may be useful:

https://stackoverflow.com/a/13755923/341994

and my answer here:

https://stackoverflow.com/a/15301322/341994




回答2:


Add an observer to the viewDidLoad method of the view you want to rotate like this :

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(orientationChanged:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

and then set the views according the the view you want to change inside the orientationChanged method like this :

- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:

        break;
    case UIDeviceOrientationPortraitUpsideDown:

        break;
    case UIDeviceOrientationLandscapeLeft:

        break;
    case UIDeviceOrientationLandscapeRight:

        break;

    default:
        break;
  };
}



回答3:


In iOS 6, the app supported orientations (stated in Info.plist) are AND'ed with the top view controller supported orientations, so in order to accomplish what you want, you need to declare support for every orientation in Info.plist, and then override the supportedOrientations: method in the view controllers where you don't want rotation to take place, for example:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


来源:https://stackoverflow.com/questions/16376237/do-supported-interface-orientations-have-precedent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!