0

How do I force my view controller to stay in portrait mode programmatically? I have created a share extension for my iOS app and I need my view to stay in portrait mode all of the time, despite the orientation of the device. The override methods below do not work:

override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientation.Portrait.rawValue)
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return UIInterfaceOrientation.Portrait
}

override func shouldAutorotate() -> Bool {
    return false
}
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Arvin Zadeh
  • 103
  • 1
  • 8
  • A share extension appears in another app, not yours. Your code has no say in that app's orientation. – matt Apr 07 '15 at 05:32
  • Matt, I understand, but the extension has its own view controller, it should be able to control that right? – Arvin Zadeh Apr 07 '15 at 05:57

1 Answers1

-1

You can use this code in viewWillApear

 let value = UIInterfaceOrientation.Portrait.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
Shruti
  • 1,849
  • 1
  • 13
  • 21