2013-09-26 43 views
1

當我轉動我的iDevice形式縱向到橫向,屏幕旋轉罰款,但我看到的黑色邊框與它移動,這樣看起來更「真實」。我發現在iOS 7中看到很尷尬,並且很多應用程序已經對此行爲進行了測試(如Instagram)。關閉默認旋轉動畫中的iOS

我想要做的是隱藏這些黑色邊框旋轉設備時,看起來完全沒有必要。如何禁用此標準動畫?

+0

而在正常狀態下它的工作好? – Ganapathy

+0

@Ganapathy我描述的是*正常狀態* :) –

+0

是否可以共享你的屏幕(隱藏官方內容) – Ganapathy

回答

1

在父視圖控制器viewDidLoad方法補充一點:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

然後加入此方法

- (void) didRotate:(NSNotification *)notification {  

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (UIInterfaceOrientationIsLandscape(orientation) && !self.modalViewController) { 
     [self presentModalViewController:carouselView animated:YES]; 
     [Globals sharedGlobals].startedAtLandscape = YES; 
    } 

    if (UIInterfaceOrientationIsPortrait(orientation) && self.modalViewController) { 
    [self dismissModalViewControllerAnimated:YES];  
    [Globals sharedGlobals].startedAtLandscape = NO; 
    } 
} 

然後以防止動畫:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) { 
     return NO; 
    } 
    return YES; 
} 
+0

雖然你的代碼示例很主觀,我已成功地達到目的第一承諾的動畫,然後使用'[UIView的setAnimationsEnabled:NO];',然後將它的'duration'時間間隔之後設置爲'yes'。像魅力一樣工作。 –

+0

噢好,我很高興有人工作:) –

1

我發現最好的解決方法是旋轉前關閉動畫,旋轉後將其關閉。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
           duration:(NSTimeInterval)duration 
{ 
    ... 
    [UIView setAnimationsEnabled:NO]; 
} 

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    ... 
    [UIView setAnimationsEnabled:YES]; 
}