6

我正在关闭一个模态视图控制器,然后立即呈现另一个模态视图控制器,但是我目前不能在它们两个上使用动画,只有第二个。

无论如何要延迟该过程以便用户体验两种动画吗?

下面的代码目前有效,但用户显然只能看到第二个动画:

// 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];
4

4 回答 4

9

现在在当前的模态视图控制器中有一个完成块可用。请参阅此链接。这在 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];
 }];
于 2012-05-24T10:39:48.480 回答
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];

您必须仔细观察并查看第一个模态显示需要多少时间才能使动画看起来不错。

于 2012-05-24T10:38:48.400 回答
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];

}

于 2012-05-24T10:41:03.800 回答
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];
}

快乐的编码...

于 2012-05-24T10:41:32.000 回答