dfgdfg
dfgdfg

Reputation: 85

Orientation of screen?

How do I make sure that the only orientations allowed are Portrait or Upside down portrait?

I made the change in the project settings, but I'm having trouble making the change in my GameViewController.

I need to make the change in this function:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

However, the "UIInterfaceOrientationMask" structure doesn't have an option that only allows portrait and upside down portrait.

Upvotes: 1

Views: 717

Answers (2)

Bannings
Bannings

Reputation: 10479

You have to allow all orientations in the project settings, then only orientations allowed are Portrait or Upside down portrait in your viewController except the GameViewController:

// BaseViewController
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return UIInterfaceOrientationMask.Portrait.rawValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue
    } else {
        return .All
    }
}

Finally in the GameViewController:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

Upvotes: 1

rb612
rb612

Reputation: 5583

You might want to try:

return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown)

Not sure if Swift will support a bitwise operator.

Upvotes: 0

Related Questions