overAiding shouldAutorotate不在Swift 3中工作 [英] overriding shouldAutorotate not working in Swift 3

查看:282
本文介绍了overAiding shouldAutorotate不在Swift 3中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图阻止一个 UIViewController 的轮换,我无法实现。

I'm trying to prevent rotation on one UIViewController and I can't achieve that.

I做这样的事情:

open override var shouldAutorotate: Bool {
    get {
        return false
    }
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    get {
        return .portrait
    }
}

UIViewControler 仍然在旋转。 UIViewController在一个模态打开的UINavigationController里面。

And the UIViewControler stills rotating. The UIViewController is inside a UINavigationController opened modally.

我从这里看了很多问题,没有一个答案适合我。

I have looked a lot of questions from here and none answers works for me.

在Swift 2中我曾经覆盖 shouldAutorotate ,但在Swift 3中,该函数不再存在。

In Swift 2 I used to override shouldAutorotate but in Swift 3 that function doesn't exist anymore.

我如何在Swift 3中做到这一点,我曾经在Swift 2中做过什么?

How can I do that in Swift 3 what I used to do in Swift 2?

推荐答案

我不知道如果我可以多次重现这种行为,为什么要投票结束这个问题。 UIViewController 位于以模拟方式打开的 UINavigationController 内。

I don't know why is a vote to close the question if I can reproduce this behavior a lots of times. The UIViewController is inside a UINavigationController opened modally.

这就是我为解决问题所做的工作。

This is what I did to solve the problem.

我创建了这个类,并设置为 UINavigationController 我希望阻止旋转的 UIViewController

I create this class and I set to the UINavigationController that containt the UIViewController that I want to prevent to rotate

class NavigationController: UINavigationController { 

    override var shouldAutorotate: Bool {
        return false
    }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .portrait
    }

}

就是这样,它对我有用

这篇关于overAiding shouldAutorotate不在Swift 3中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆