是否有可能关闭自动旋转的动画效果?我希望它可以旋转,但不希望出现动画效果(就像瞬间切换一样)。
是否有可能关闭自动旋转的动画效果?我希望它可以旋转,但不希望出现动画效果(就像瞬间切换一样)。
如果你真的有需要,可以使用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
}
对我来说,这个方法很有效。当然,除非你有非常充分的理由,否则不建议这样做。
- (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];
}