2011-09-17 244 views
0

什麼是正確的方式來實現類似於iPhone的標準iPod應用程序中的效果 - 當設備旋轉到橫向模式時,視圖改變爲覆蓋流程,但是過渡類型是淡入淡出而不是旋轉屏幕?IOS旋轉設備不旋轉動畫

這是怎麼了加載模式的看法:

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
     carouselView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
     [self presentModalViewController:carouselView animated:YES]; 
    } 
} 

謝謝!

安德

回答

2

我後來發現它是更穩定的,以使用此解決方案:

在父視圖控制器(在我的情況下,它是選項卡視圖控制器)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

presentModalViewController已被棄用。 –