简体   繁体   中英

Force portrait orientation IOS (swift)

I'm trying to force portrait orientation on iphone. So i try this:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return .Landscape
}

But i have an error: "Method does not override any method from its superclass"

supportedInterfaceOrientations() is a function from UIViewController . If you are getting this error "Method does not override any method from its superclass" which means your class is not inherited from UIViewController. Maybe you can give additional info about the class you try to implement an orientation.

Use it like the below code snippet,

override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
    return .landscape
}

This has been converted into a property now and you should override them and return a value like a computed property. Since your question says you are trying to force a portrait orientation, you should return .portrait or UIInterfaceOrientationMask.portrait instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM