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?
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")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With