Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method like didRotateFromInterfaceOrientation which happens during rotation in Swift?

I am trying to .StartAnimating an UIActivityIndicator when I rotate the device, I was trying to use an override function: didRotateFromInterfaceOrientation; however, this function is called after rotation has occurred and I would like to animate during the actual rotation.

I am looking for a method which is called at the moment of rotation. I have looked through the literature, and have found only depreciated functions that might have worked.

Are there any current methods that I could use for this?

like image 357
George Lee Avatar asked Dec 11 '22 19:12

George Lee


1 Answers

Just use this code snippet to check the orientation changes

Swift 1.x/2.x

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        print("Landscape")
    } else {
        print("Portrait")
    }
}

Swift 3.x

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.current.orientation.isLandscape {
        print("Landscape")
    } else {
        print("Portrait")
    }
}
like image 134
Rashwan L Avatar answered Dec 13 '22 08:12

Rashwan L