Recusiwe
Recusiwe

Reputation: 900

ViewWillTransitionToSize broke in Swift 3?

I'm using viewWillTransitionToSize to adjust my slideout menu when I rotate the device, however it seems to be broken in Swift 3? Can anyone solve this for me? My code looks like this:

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!
        })
    }

It seems like it doesn't get called when I rotate the device?

Upvotes: 7

Views: 8899

Answers (1)

Recusiwe
Recusiwe

Reputation: 900

Figured out what the problems was, the changes the migration to swift 3 made was not proper, and the function should look like this:

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!
        })

    }

Upvotes: 14

Related Questions