Home > other >  Programmatically rotate NavBar in objective-c
Programmatically rotate NavBar in objective-c

Time:05-07

Is it possible to programmatically rotate navBar on rotation in objective-c, when Device Orientation in Deployment info is set to Portrait only?

CodePudding user response:

  1. Set the allowed orientations to both Portrait & Landscape in your project settings
  2. Set all your view controllers to allow only portrait orientation and no rotation
  3. On the view controllers that require landscape set the preferred orientation to landscape.
override public var shouldAutorotate: Bool {
    return false
}

override public var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .landscapeRight
}

override public var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeRight
  }
}
  • Related