I need to disable the animation that plays when the orientation changes. Is this possible? If not, is it possible to speed it up?
Just to clarify, i don't want to stop the orientation change, just the animation. I want an instant orientation change.
If I remember correctly (this is always the sort of thing I have to play around with for a moment to get right)
willRotateToInterfaceOrientation:duration:
andwillAnimateRotationToInterfaceOrientation:duration:
are both inside the animation block, whiledidRotateFromInterfaceOrientation:
runs after the animation block. I believe you would need to lay out your views inwillRotate
so they appear in the position in which they would appear after the rotation had they not rotated (if that makes sense). This way the animation will animate them from their original (correct) layout to the new (rotated) layout in the opposite direction that the device rotates, creating the appearance of no animation. Once the rotation is complete, you can lay out your views, without animation, indidRotate
, giving the impression that they rotate instantly.Clear as mud, no?
Based on Nils Munch's Answer, this is the Swift 3 version:
if you re-layout your views when the view is about to be rotated I think when it really rotates it won't have animations. I mean, write a method with the new coordinates, frames, positions for each subview and call that method in
willRotateToInterfaceOrientation:duration:
orwillAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
(This is not a smart way of doing things though. I wonder, why do you need no-animation?)In iOS8 you can disable rotation animations by disabling CALayer animations in your view controller's implementation of
viewWillTransitionToSize
.The inverse rotation mentioned in the accepted answer is useful if you want to customize the transition (see WWDC 2014 'View Controller Advancements in iOS 8') but not if you just want to prevent animation.
(N.B. Implementing
viewWillTransitionToSize
will prevent the deprecated pre-iOS8 rotation APIs from being called.)Yes, it is possible to disable the animation, without breaking everything apart.
The following codes will disable the "black box" rotation animation, without messing with other animations or orientation code:
Place it in your UIViewController and all should be well. Same method can be applied to any undesired animation in iOS.
Best of luck with your project.
For 2016, it appears
shouldAutorotateToInterfaceOrientation
is not available to be overridden. The following does seem to work, and cause no other harm.However!! Indeed both these functions are deprecated.
viewWillTransitionToSize
now takes care of both the "before" and "after".