【问题标题】:swift UIView Animation completion handler calls firstswift UIView 动画完成处理程序首先调用
【发布时间】:2020-06-10 17:43:33
【问题描述】:

我找到了一个不错的 curl 视图动画,我想在完成后添加 segue,但 segue 是先调用的(即使返回 viewcontroller 我也可以看到动画结束)。请帮我找出错误或实现目标的方法

UIView.animate(withDuration: 1, animations: {
            let animation = CATransition()
            animation.duration = 1
            animation.startProgress = 0.0
            animation.endProgress = 1
            animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
            animation.type = CATransitionType(rawValue: "pageCurl")
            animation.subtype = CATransitionSubtype(rawValue: "fromRight")

            animation.isRemovedOnCompletion = false
            animation.isRemovedOnCompletion = false
            self.selectedCell!.view1.layer.add(animation, forKey: "pageFlipAnimation")

        }, completion: { _ in

            let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "PageVC") as? PageVC
             secondViewController!.modalPresentationStyle = .fullScreen
             self.navigationController?.present(secondViewController!, animated: false, completion: nil)
        })

【问题讨论】:

    标签: ios swift core-animation uiviewanimation


    【解决方案1】:

    您正在做的是尝试将动画添加到视图中。 动画块需要 1 秒才能完成。基本上,它试图在一秒钟内对动画的添加进行动画处理。完成后,它开始导航。 您可以使用 CATransaction 来创建所需的功能,而不是这样做。

    CATransaction.begin()
    CATransaction.setCompletionBlock {
        if let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "PageVC") as? PageVC {
            secondViewController.modalPresentationStyle = .fullScreen
            self.navigationController?.present(secondViewController, animated: false, completion: nil)
        }
    }
    
    let animation = CATransition()
    animation.duration = 1
    animation.startProgress = 0.0
    animation.endProgress = 1
    animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
    animation.type = CATransitionType(rawValue: "pageCurl")
    animation.subtype = CATransitionSubtype(rawValue: "fromRight")
    
    animation.isRemovedOnCompletion = false
    animation.isRemovedOnCompletion = false
    self.selectedCell!.view1.layer.add(animation, forKey: "pageFlipAnimation")
    
    CATransaction.commit()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-02
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      相关资源
      最近更新 更多