应用移至后台时,UIPropertyAnimator调用完成

时间:2019-08-19 10:17:09

标签: swift animation uiviewpropertyanimator

我有观点认为,当定时器值相等时,它开始下降。 但是,当应用移至后台时,我在每个 propertyAnimator视图上调用 pauseAnimation(),但是 PropertyAnimator 调用完成,并从每个已经开始的视图中删除动画。 当应用程序激活时,这些视图将无效,我什么也不能做

 animation!.addCompletion { [unowned self] position in
            switch position {
            case .end:
                animatedNote.isStopped = true
                self.pauseAnimationTimer()
            case .current:
                animatedNote.isPlaying = false
                animation = nil
            case .start:
                UIView.animate(withDuration: 0.3, animations: {
                    pianoView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
                }, completion: { _ in
                    pianoView.removeFromSuperview()
                    animation = nil
                })

            @unknown default:
                fatalError()
            }
        }



   func pauseAnimationTimer() {

    timer.suspend()
    DispatchQueue.global(qos: .userInteractive).async { [unowned self] in


        self.timerPaused = true
        if !self.animators.isEmpty {
        for (index,animator) in self.animators.enumerated() {
            if animator != nil,animator!.isPlaying {
                DispatchQueue.main.async {
                    if !animator!.isStopped {
                        animator!.propertyAnimator?.pauseAnimation()
                    }
                }
            }
        }
    }
}

0 个答案:

没有答案