Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NoRotate
//In the controllers to not rotate
override var shouldAutorotate : Bool {
return false
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
//otherwise i did not change anything. and as long as all orientations are supported if you don't set above it will rotate.
// on dismiss i think it reoriented but i might have ask for layout or something cannot remember.
// i think in the case of collectionviews i might have had to invalidate layout in viewwillappear but cannot remember
//navigation controller if you need it
import UIKit
class MainNavViewController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override var shouldAutorotate: Bool {
if !viewControllers.isEmpty{
return self.topViewController!.shouldAutorotate
}else{
return true
}
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
if !viewControllers.isEmpty{
return self.topViewController!.supportedInterfaceOrientations
}else{
return self.supportedInterfaceOrientations
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment