When you set programmatically the orientation of the device. To perform the orientation animation the function
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
from AppDelegate
is being called.
If you have set it there to return only UIInterfaceOrientationMask.portrait
you will never see the transition.
Also I personally have these kind of problems and to solve this I had to programmaticaly force the phone to rotate to the current Orientation and then to rotate to the wanted orientation.
Example for phone to rotate landscapeLeft from portrait
func setOrientationToLandScapeOnly() {
appDelegate.shouldForceLandscapeOnly = true
appDelegate.shouldForcePortraitOnly = false
if UIDevice.current.userInterfaceIdiom == .phone {
switch UIApplication.shared.statusBarOrientation {
case .landscapeLeft, .landscapeRight:
return
default:
APIOrientationHandler.shared.setDeviceValueForOrientation(UIInterfaceOrientation.portrait.rawValue)
APIOrientationHandler.shared.setDeviceValueForOrientation(UIInterfaceOrientation.landscapeLeft.rawValue)
return
}
}
}
And inside AppDelegate.swift
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if shouldForcePortraitOnly {
return UIInterfaceOrientationMask.portrait
}
if shouldForceLandscapeOnly {
return UIInterfaceOrientationMask.landscape
}
if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
return UIInterfaceOrientationMask.landscape
}
return UIInterfaceOrientationMask.portrait
}