This question is strictly about iOS9+
Say you have an ordinary modern app (autolayout, storyboard, universal) which does allow all four rotation positions
you want it to autorotate in the normal way, so it will change to your new constraint-based layouts when user rotates device from landscape to portrait
But you simply want NO animation during the user rotating the device. You want it to just "click" to the new sideways or upright layout.
The only way I have been able to achieve this is by adding:
override func viewWillTransitionToSize(size:CGSize,
withTransitionCoordinator coordinator:UIViewControllerTransitionCoordinator)
{
coordinator.animateAlongsideTransition(nil, completion:
{_ in
UIView.setAnimationsEnabled(true)
})
UIView.setAnimationsEnabled(false)
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator);
}
to one view controller, a highest or near-highest VC which holds the rest of the container views or whatever in the scene.
This is basically the same ancient idea of using willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation (both now unusable in modern iOS) to turn animations on-off.
However there are many problems
this does not work AppWide, it is a mess, it is scene-based
it seems Very Bad to just turn off all animations
you can see all sorts of racetrack
This question is strictly about iOS9+
These days, Is there any better way to turn off the rotation animations in an app which supports landscape/portrait ???
This question is strictly about iOS9+
UIView.areAnimationsEnabled()
returnstrue
inside the animation block, which puzzles me (as it is indeed disabled before). There must be a timing issue with the rotation animation block... (setAnimationsEnabled
doc states:"This method affects only those animations that are submitted after it is called. If you call this method while existing animations are running, those animations continue running until they reach their natural end point.") – Alumroot