Handling autorotation for one view controller in iOS7

前端 未结 5 1469
野趣味
野趣味 2020-12-06 02:37

I\'ve read many answers on SO but I can\'t seem to get autorotation working on iOS7.

I only need one view controller to rotate, so I don\'t want to set rotation sett

5条回答
  •  没有蜡笔的小新
    2020-12-06 03:03

    In my case, I had a new iOS7 app with about 30 view controllers created already. I needed auto rotation on just a single modal view controller. I didn't want to have to update the preexisting view controllers.

    I selected the orientations I wanted in the plist:

    select orientations

    Then I added a category to my app delegate on UIViewController:

    @implementation UIViewController (rotate)
       -(BOOL)shouldAutorotate {
          return NO;
       }
    @end
    

    Then in the single modal view controller I WANTED to rotate I added this method:

    -(BOOL)shouldAutorotate {
          return YES;
    }
    

    I also discovered, that if my view controller wasn't a modal VC I would need to add category methods on UINavigationController instead, for all VCs that were subsequent to the root view controller, as part of the navigation stack of view controllers - similar to this: https://stackoverflow.com/a/20283331/396429

提交回复
热议问题