Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

iphone - Disable orientation change rotation animation

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [UIView setAnimationsEnabled:YES];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    [UIView setAnimationsEnabled:NO];
  /* Your original orientation booleans*/

    return TRUE;
}

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.

// these DO SEEM TO WORK, 2016
override func willRotateToInterfaceOrientation(
        toInterfaceOrientation:UIInterfaceOrientation, duration:NSTimeInterval)
    {
    UIView.setAnimationsEnabled(false)
    super.willRotateToInterfaceOrientation(toInterfaceOrientation,duration:duration)
    }
override func didRotateFromInterfaceOrientation(
        fromInterfaceOrientation:UIInterfaceOrientation)
    {
    super.didRotateFromInterfaceOrientation(fromInterfaceOrientation)
    UIView.setAnimationsEnabled(true)
    }

However!! Indeed both these functions are deprecated. viewWillTransitionToSize now takes care of both the "before" and "after".

override func viewWillTransitionToSize(size:CGSize,
       withTransitionCoordinator coordinator:UIViewControllerTransitionCoordinator)
    {
    coordinator.animateAlongsideTransition(nil, completion:
        {_ in
        UIView.setAnimationsEnabled(true)
        })
    UIView.setAnimationsEnabled(false)
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...