2010-06-01 75 views
4

是否可以关闭自动旋转动画?我希望它旋转,但我不想让动画发生(像即时切换)。iphone autorotation动画

+0

动画是它的美丽! – 2010-06-01 12:09:24

+0

嗯,我已经设置好了,使得BG图像根据方向改变为图像的水平或垂直版本,并且当图像改变时旋转动画引起毛刺,但是我玩了它并且看起来像它无论如何,好吧。 – Brodie 2010-06-01 16:31:55

回答

4

只需添加以下代码来覆盖标准的旋转动画:

- (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]; 
} 
+1

这个答案效果很好,但是我在聚焦文本框时遇到了一些问题。如果iPad平放在桌面上,那么键盘在屏幕外显示一半 - 非常奇怪。 问题在于设备方向也可能未知,面朝上或面朝下,其中没有一个对应于状态栏方向。检查这些状态使这个完美。 非常感谢尼尔斯为我挽救了这个解决方案:) – 2012-06-23 03:21:03

+0

+1 adam为你贡献:] – 2012-06-23 08:21:30

+0

什么是“定位”? – Morkrom 2013-08-28 21:43:07

7

如果你真的需要,只是用setAnimationsEnabledUIView的:

- (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 
} 

它的伎俩我。当然,除非你有充分的理由去做,否则不建议这样做。

+0

这太好了!谢谢! – 2012-04-13 07:05:06

0

@Nils Munch不幸的是,这不能正常工作,setStatusBarOrientation期望UIInterfaceOrientationUIDeviceOrientation和铸造是不好的做法。纠正我,如果我错了