Iphone autorotation animation

Is it possible to disable animation for autorotation? I want it to rotate, but I just don't want the animation to happen (like an instant switch).

+4
source share
3 answers

Just add the following code to overwrite the standard rotation animation:

- (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)didRotate:(NSNotification *)notification { orientation = [[UIDevice currentDevice] orientation]; if(orientation == UIDeviceOrientationUnknown || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationFaceUp){ orientation = UIDeviceOrientationPortrait; } [[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:NO]; [self positionScreenElements]; } 
+4
source

If you really need to, just use setAnimationsEnabled for a UIView :

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [UIView setAnimationsEnabled:NO]; // disable animations temporarily } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [UIView setAnimationsEnabled:YES]; // rotation finished, re-enable them } 

This is a trick for me. Of course, this is not recommended unless you have a good reason for this.

+7
source

@Nils Munch, unfortunately, this does not work properly, setStatusBarOrientation expects UIInterfaceOrientation not UIDeviceOrientation , and casting is bad practice. Correct me if I am wrong

0
source

Source: https://habr.com/ru/post/1311466/


All Articles