如何解雇淡出animation的模态VC?

我在我的演示文稿中使用下面的代码来淡入子模态VC,并且这工作正常:

self.infoViewController.view.alpha = 0.0; [self.navigationController presentModalViewController:self.infoViewController animated:NO]; [UIView animateWithDuration:0.5 animations:^{self.infoViewController.view.alpha = 1.0;}]; 

但是我不能让它淡出,我已经尝试了一些东西,这是最新的,我试过,这是行不通的:

 - (IBAction)dismissAction:(id)sender { if ([[self parentViewController] respondsToSelector:@selector(dismissModalViewControllerAnimated:)]) { [[self parentViewController] dismissModalViewControllerAnimated:YES]; self.parentViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; self.parentViewController.view.alpha = 0.0; [UIView animateWithDuration:0.5 animations:^{self.parentViewController.view.alpha = 1.0;}]; } else { [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; self.presentedViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; self.presentedViewController.view.alpha = 0.0; [UIView animateWithDuration:0.5 animations:^{ self.presentedViewController.view.alpha = 1.0;}]; } 

}

模态视图控制器淡出,但立即,而不是像它的显示时间段。

这(原始部分)不是从H2CO3的正确答案中拿走的。 UIModalTransitionStyleCrossDissolve完成你正在寻找的效果。 你只是没有设置modalTransitionStyle,直到它迟到。 用相应的位置replace您所有的代码:

 -(void)show{ self.infoViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:self.infoViewController animated:YES]; } - (IBAction)dismissAction:(id)sender{ [self dismissModalViewControllerAnimated:YES]; } 

编辑时间是一个问题:让我们来谈谈有问题的代码。 我们将专注于真正的部分,因为它与其他部分基本相同。

 [[self parentViewController] dismissModalViewControllerAnimated:YES]; self.parentViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; self.parentViewController.view.alpha = 0.0; [UIView animateWithDuration:0.5 animations:^{self.parentViewController.view.alpha = 1.0;}]; 

如果你正在寻找一个互惠animation,这不是。 在原始animation中,将下一个视图的alpha设置为0,然后展示下一个视图控制器,然后将其视图的alpha设置为1.因此,在逻辑上,需要在animation之后closures视图控制器; 这很容易使用块。 代码看起来像这样:

 [UIView animateWithDuration:0.5 animations:^{ self.view.alpha = 0; } completion:^(BOOL b){ [self.presentingViewController dismissModalViewControllerAnimated:NO]; self.view.alpha = 1; }]; 

这行代码将视图的alpha值设置为0,然后(完成时)closures呈现的视图控制器,并将视图的alpha设置回1.这是一个倒数animation。

在UIViewController的文档中,我们可以find:

 @property(nonatomic, assign) UIModalTransitionStyle modalTransitionStyle 

将此属性设置为UIModalTransitionStyleCrossDissolve ,它将正确解散:)

希望有所帮助。

我想,这对于那些仍然试图在全屏模式下使用MPMoviePlayerViewController的英雄家伙来说可能是有用的。

我花了半天的时间玩模式或不模态地呈现MPMoviePlayerViewController 。 但是,根本就没有运气,因为过渡animation的变化。 (设置不同于应用主要方向的方向所需的模式模式)。

我试过presentViewController或presentModalViewController,但结果是一样的。 不pipe是什么types的modalTransitionStyle属性设置,如果我做[… dismissViewControllerAnimated:true …]那么默认的过渡样式(UIModalTransitionStyleCoverVertical)无论如何。 我在iOS 5.1设备和iOS 6模拟器中进行了testing。

我还没有尝试任何其他types的控制器…考虑到常见的控制器有方法dismissMoviePlayerViewControllerAnimated,我可以假设,无论如何,这种方法被用来解雇一个video控制器,不pipe它是如何出现的。 (input转换对我来说也不起作用,除非它们不作为CoverVertical进行处理(在modalTransitionStyle更改的情况下)。

所以,我的解决scheme根本不使用过渡animation 。 我肯定,苹果有一些理由只允许一些明确的animationMovieViewController(我真的希望如此,这不是因为“懒惰”),但如果他们想要一些不错的经验用户会得到,他们失败了,如在我的应用程序,当video出现没有任何animation时(甚至比CrossDisolve更糟糕),这样的效果会更好,但这比平常的CoverVertical更好。

从开发人员的angular度来看,这听起来像是他们花费了更多的钱为devise师绘制漂亮的图标给客户,而不是开发人员更愉快和有效的工作。

Interesting Posts