【问题标题】:How to transition to a modalViewController without stopping the animation while transitioning如何在过渡时不停止动画的情况下过渡到 modalViewController
【发布时间】:2012-06-14 13:41:18
【问题描述】:

我注意到,如果我在控制器“A”的某个元素上启动 UIView 动画并呈现带有过渡的控制器 B,则之前提交的动画不会启动。 例如:

//apply a UIView animation before transitioning
[UIView animateWithDuration: 1 delay:0 options:UIViewAnimationOptionCurveEaseOut             animations:^{
        someUIView.frame = newFrame;
 }completion:nil];
//transition from  controller A to controller B
controllerB.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: controllerB animated:YES];

如果动画已经开始并且我尝试转换到控制器 B,则 A 中的动画会停止。我注意到这种行为取决于使用的转换类型。例如,如果使用“UIModalTransitionStyleCoverVertical”,则不会出现问题。 有什么想法吗?

【问题讨论】:

  • 你确定它没有启动吗?可能,你只是错过了它!因为如果它发生在一个中,它也应该与其他过渡样式一起发生......
  • 我确定它不会启动。如果它已经开始,它将在过渡开始时停止。试试看 ;) 还要在 iPhone 模拟器中打开“慢动画”。
  • 嗯...我想我明白它为什么停止了。看,在UIModalTransitionStyleCoverVertical 中,主视图的层没有被触及。在其他过渡样式中,对主视图的图层进行快照,并在该快照/图层上完成过渡动画。所以它正在发生,但您只能看到在动画开始之前创建的图层。这就是过渡动画的工作原理,所以我认为这应该是对这种异常的解释。
  • 快照没有改变以反映正在发生的动画,所以我们看不到它发生。
  • @tipycalFlow 这是一个很好的解释。大概就是这样。不幸的是,当您在从一个控制器转换到另一个控制器时显示/隐藏键盘时使用 UIview 动画移动元素时,“冻结”动画看起来不太好。但我想我无能为力,除了使用不拍摄(或光栅化)图层的过渡。

标签: objective-c ios uiviewcontroller core-animation uiviewanimation


【解决方案1】:

只需从动画完成块中展示您的控制器B

[UIView animateWithDuration: 1 
                      delay:0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     someUIView.frame = newFrame;
                }completion:^{
                   //transition from  controller A to controller B
                   controllerB.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
                   [self presentModalViewController: controllerB animated:YES];
 }];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 2021-03-10
    • 2015-05-07
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    相关资源
    最近更新 更多