Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewWillTransitionToSize broke in Swift 3?

Tags:

ios

swift

swift3

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?

like image 828
Recusiwe Avatar asked Sep 26 '16 14:09

Recusiwe


1 Answers

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

    }
like image 101
Recusiwe Avatar answered Oct 21 '22 23:10

Recusiwe