Disable orientation change rotation animation

后端 未结 5 2158
南方客
南方客 2020-12-01 00:50

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 s

5条回答
  •  粉色の甜心
    2020-12-01 01:43

    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.)

    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator
    {
        [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
        [CATransaction begin];
        [CATransaction setDisableActions:YES];
        [coordinator animateAlongsideTransition:^(id context) {
            // You could make a call to update constraints based on the
            // new orientation here.
        } completion:^(id context) {
            [CATransaction commit];
        }];
    }
    

提交回复
热议问题