简体   繁体   English

方向更改时更改或禁用iPhone旋转动画

[英]Change or disable the iPhone rotating animation when orientation changes

当屏幕方向从横向更改为纵向时,如何更改或禁用旋转动画,反之亦然?

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. 把它放在你的UIViewController中,一切都很好。 Same method can be applied to any undesired animation in iOS. 相同的方法可以应用于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 . 如果您不希望视图控制器旋转,只需覆盖shouldAutoRotateToInterface视图控制器方法,以便为您不想支持的任何方向返回false ... 这是一个参考

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 在你只是想以其他方式处理旋转的情况下,你可以在上面的方法中返回false并注册UIDeviceOrientationDidChangeNotification,就像这样

    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. @Nils Munch上面的答案是找到<iOS7。 For iOS 7 or later you can use: 对于iOS 7或更高版本,您可以使用:

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

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

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM