没有调用Swift 3 viewWillTransitionToSize

时间:2016-10-17 13:14:28

标签: swift

我的swift 3代码中有这个方法:

func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
}

我尝试了以下内容:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
}

但是我收到了这个错误:

Method does not override any method from its superclass

为什么不调用viewWillTransitionToSize?

2 个答案:

答案 0 :(得分:2)

尝试

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator){
    super.viewWillTransition(to: size, with: coordinator)
}

答案 1 :(得分:1)

关于从swift2.x迁移到Swift3'viewWillTransition'方法的迁移过程已经改变:

<强> Swift2.x

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)

<强> Swift3

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)

使用 将密钥 withTransitionCoordinator 更改为