[英]iPhone - UIViewController not rotating when device orientation changes
[英]Change or disable the iPhone rotating animation when orientation changes
当屏幕方向从横向更改为纵向时,如何更改或禁用旋转动画,反之亦然?
是的,可以禁用动画,而不会破坏一切。
以下代码将禁用“黑匣子”旋转动画,而不会弄乱其他动画或方向代码:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[UIView setAnimationsEnabled:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[UIView setAnimationsEnabled:NO];
/* Your original orientation booleans*/
}
把它放在你的UIViewController中,一切都很好。 相同的方法可以应用于iOS中的任何不需要的动画。
祝你的项目好运。
如果您不希望视图控制器旋转,只需覆盖shouldAutoRotateToInterface视图控制器方法,以便为您不想支持的任何方向返回false ... 这是一个参考 。
在你只是想以其他方式处理旋转的情况下,你可以在上面的方法中返回false并注册UIDeviceOrientationDidChangeNotification,就像这样
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(handleOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
现在,当你收到通知时,你可以随心所欲地做任何事......
@Nils Munch上面的答案是找到<iOS7。 对于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.