开发者

Change or disable the iPhone rotating animation when orientation changes

开发者 https://www.devze.com 2022-12-28 19:56 出处:网络
How do I change or disable the rotating animation when screen orientation changes from landscape to portrait, or vice ve开发者_如何学Crsa?Yes, it is possible to disable the animation, without breaking

How do I change or disable the rotating animation when screen orientation changes from landscape to portrait, or vice ve开发者_如何学Crsa?


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*/
}

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.


If you dont want your view controllers to rotate just override the shouldAutoRotateToInterface view controller method to return false for whichever orientation you dont want to support...Here is a reference.

In the case that u just want to handle rotation some other way, you can return false in the above methods and register for UIDeviceOrientationDidChangeNotification like so

    NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
       selector:@selector(handleOrientationDidChange:)
           name:UIDeviceOrientationDidChangeNotification
         object:nil];

Now when u get the notifications u can do whatever you want with it...


The answer by @Nils Munch above is find for < iOS7. For iOS 7 or later you can use:

- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [UIView setAnimationsEnabled:NO];

    [coordinator notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        [UIView setAnimationsEnabled:YES];
    }];

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号