2010-06-01 73 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和鑄造是不好的做法。糾正我,如果我錯了