Stop a modal UIViewController from rotating

自作多情 提交于 2019-12-01 09:21:35

Basically, if you presenting Modal Controller on Any Container Controllers (i.e. UINavigationController) it have autorotation method return YES by default. So you have to make subclass for your UINavigation Controller and Deprecate Autorotation there.

For iOS 5 use method:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

    return (toInterfaceOrientation == UIInterfaceOrientationPortrait) : self.enableRotations;
}

for iOS 6:

- (NSUInteger)supportedInterfaceOrientations {

    switch ([UIDevice currentDevice].userInterfaceIdiom) {

        case UIUserInterfaceIdiomPad:   return UIInterfaceOrientationMaskAll;
        case UIUserInterfaceIdiomPhone: return UIInterfaceOrientationMaskPortrait;
    }
}

- (BOOL)shouldAutorotate {

    return NO;
}

It can be doable, but I would think twice before doing that.

As a user;

  • I launch the app and use in landscape.
  • trigger an event (eg. press button).
  • see a view which is portrait.
  • rotate the phone and look in portrait.
  • close the modal view.
  • get landscape view again.
  • need to rotate the phone again

Bad usability...

you have to present that new controller on a new navigation controller.This will solve your problem

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