2012-05-24 32 views
6

我正在關閉一個模式視圖控制器,然後立即呈現另一個模式視圖控制器,但我目前無法使用這兩個動畫只有第二個。如何在2個動畫之間進行延遲?

是否有延遲過程,以便用戶體驗這兩個動畫?

下面的代碼當前工作但用戶只能看到明顯的第二個動畫:

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

//Dismiss first one 
[self dismissModalViewControllerAnimated:NO]; 

//Immediately configure and show second one 
navController.modalPresentationStyle = UIModalPresentationFormSheet; 
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:navController animated:YES]; 
+0

我可以假設你已經嘗試過' [自dismissModalViewControllerAnimated:YES];'不成功?? –

+0

[UIView transitionWithView:mysuperview duration:0.75 options:UIViewAnimationTransitionFlipFromRight animations:^ {[self dismissModalViewControllerAnimated:NO]; }完成:無] –

回答

9

現在在當前的模態視圖控制器中有一個完整塊。看到這個LINK。這在iOS5.0 +中可用。

這樣做的好處是,如果您使用定時器解決方案,則無需估計定時器延遲。

只要把代碼爲你的第二個動畫塊:

//Block safe reference to self to prevent retain cycles 
__block typeof (self) selfReference = self; 

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES completion: 
^{ 
    //Dismiss first one 
    [selfReference dismissModalViewControllerAnimated:NO]; 

    //Immediately configure and show second one 
    navController.modalPresentationStyle = UIModalPresentationFormSheet; 
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [selfReference presentModalViewController:navController animated:YES]; 
}]; 
+2

這是正確的解決方案。嘗試使用計時器來猜測您的第一個視圖控制器何時完成動畫製作是一種黑客行爲。 – jnic

+0

+1對於最好的方法之一 – Mat

+0

這很棒!這兩個動畫看起來很棒,感謝隊友,再加上第一次使用塊 - 非常方便! – TheLearner

1

做一個選擇,做以下操作:

- (void)showSecondModalVC { 
    //Dismiss first one 
    [self dismissModalViewControllerAnimated:NO]; 

    //Immediately configure and show second one 
    navController.modalPresentationStyle = UIModalPresentationFormSheet; 
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:navController animated:YES]; 
} 

的然後在主一段代碼:

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

[self performSelector:@selector(showSecondModalVC) 
     withObject:nil 
     afterDelay:0.5f]; 

你將不得不仔細看看,看看第一個模態需要多少時間以顯示動畫看起來不錯。

1

您可以在其他一些風格做到這一點。

detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

[self dismissModalViewControllerAnimated:NO]; 

[self performSelector:@selector(someFunction) withObject:nil afterDelay:1.0]; 

- (void) someFunction{ 
//Immediately configure and show second one 
navController.modalPresentationStyle = UIModalPresentationFormSheet; 
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:navController animated:YES]; 

}

1

試試這個:

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

//Dismiss first one 
[self dismissModalViewControllerAnimated:NO]; 
NSTimer Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(openSecondView) userInfo:nil repeats:NO]; 


-(void)openSecondView 
{ 
    //Immediately configure and show second one 
    navController.modalPresentationStyle = UIModalPresentationFormSheet; 
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:navController animated:YES]; 
} 

編碼快樂......