ViewWillTransitionToSize在Swift 3中爆发了吗?

时间:2016-09-26 14:52:01

标签: ios swift swift3

我在旋转设备时使用viewWillTransitionToSize来调整我的滑出菜单,但它似乎在Swift 3中被打破了?有人能为我解决这个问题吗?我的代码如下所示:

func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        coordinator.animate(alongsideTransition: nil, completion: {
            _ in

            let controller = self.revealViewController().rightViewController

            var frame = controller?.view.frame
            frame?.size.height = UIScreen.main.bounds.size.height - self.navigationController!.navigationBar.frame.size.height - self.toolBar.frame.size.height - (UIApplication.shared.isStatusBarHidden ? 0 : 20)
            controller?.view.frame = frame!
        })
    }

旋转设备时似乎没有调用它?

1 个答案:

答案 0 :(得分:14)

弄清楚问题是什么,迁移到swift 3所做的更改是不正确的,而且函数看起来应该是这样的:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        coordinator.animate(alongsideTransition: nil, completion: {
            _ in

            let controller = self.revealViewController().rightViewController

            var frame = controller?.view.frame
            frame?.size.height = UIScreen.main.bounds.size.height - self.navigationController!.navigationBar.frame.size.height - self.toolBar.frame.size.height - (UIApplication.shared.isStatusBarHidden ? 0 : 20)
            controller?.view.frame = frame!
        })

    }