[英]iphone autorotation animation
Is it possible to turn off the animation for the autorotation? 是否可以关闭自动旋转的动画? I want it to rotate, but I just dont want the animation to occur (like an instant switch).
我想让它旋转,但我只是不想要动画发生(就像一个即时开关)。
If you really need to, just use setAnimationsEnabled
of UIView
: 如果你真的需要,只需使用
UIView
setAnimationsEnabled
:
- (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
}
It does the trick for me. 这对我有用。 Of course it's not recommended to do this unless you have a very good reason to do it.
当然,除非你有充分的理由这样做,否则不建议这样做。
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];
}
@Nils Munch unfortunately this does not work properly, the setStatusBarOrientation expects UIInterfaceOrientation
not UIDeviceOrientation
and casting is bad practice. @Nils蒙克不幸的是,这并不正常工作,setStatusBarOrientation预计
UIInterfaceOrientation
不UIDeviceOrientation
和铸造是不好的做法。 Correct me if I am wrong 如果我错了,请纠正我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.