Force portrait mode

前端 未结 2 1379
无人共我
无人共我 2021-01-26 03:29

Alright, since no one answered my previous question, I have come to believe that there may be no easy way to do this. But I am optimistic. Here\'s my issue:

In my app, I

2条回答
  •  孤街浪徒
    2021-01-26 03:47

    Check the question How to handle different orientations in iOS 6. See the answer there for a project example of exactly what you need.

    Basically you need to embed a custom navigation controller in your viewcontroller (the one you want to rotate). Add the following method in this custom navigation controller (it is for landscape orientation but you can replace it for portrait)

    - (NSUInteger)supportedInterfaceOrientations
    {
        return self.topViewController.supportedInterfaceOrientations;
    }
    

    and add to your view controller that should rotate:

    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    

    Be sure Portrait, Landscape Right and Landscape Left orientations are enabled in your project. Then, if you want to block some orientations for a particular view:

    – application:supportedInterfaceOrientationsForWindow:
    

提交回复
热议问题