簡體   English   中英

出現模態視圖 controller 時暫停 animation

[英]Pause animation when modal view controller is presented

我有兩個 animation 在我的主屏幕視圖 controller 上播放。 它們都是來自 LottieFiles 的動畫。 一個是 alpha 顏色變化的背景,另一個是具有不同 colors 的無限循環。 When a new modal view over current context is selected I want to pause both animations and start them up again once the modal view is dismissed. 我曾嘗試調用 animationView.pause 方法,但它們仍會繼續在后台播放。我想暫停它們以提高能源效率。

      class HomeScreen: UIViewController{
 let animationView = AnimationView()
 let animationTwo = AnimationView()

 func showSupport() {

    let modalViewController = SupportViewController()
    modalViewController.modalPresentationStyle = .overCurrentContext
    present(modalViewController, animated: true, completion: nil)
}
 func showSInfo() {

    let modalViewController = InfoViewController()
    modalViewController.modalPresentationStyle = .overCurrentContext
    present(modalViewController, animated: true, completion: nil)
}
override func viewDidAppear(_ animated: Bool) {

    super.viewDidAppear(animated)


    animationView.play(fromProgress: 0,
                       toProgress: 1,
                       loopMode: LottieLoopMode.loop,
                       completion: { (finished) in
                        if finished {
                            print("Animation Complete")
                        } else {
                            print("Animation cancelled")
                        }
    })


    animationTwo.play(fromProgress: 0,
                       toProgress: 1,
                       loopMode: LottieLoopMode.loop,
                       completion: { (finished) in
                        if finished {
                            print("Animation Complete")
                        } else {
                            print("Animation cancelled")
                        }
    })

}
 override func viewDidLoad() {
   let animation = Animation.named("bg12")
    animationView.animation = animation
    animationView.contentMode = .scaleAspectFill
    view.addSubview(animationView)

    let animationViewTwo = Animation.named("infi2")
    animationTwo.animation = animationViewTwo
    animationTwo.contentMode = .scaleAspectFit
    animationTwo.alpha = 0.7
    view.addSubview(animationTwo)
 }
    }


 class SupportViewController: UIViewController {
     let homeVC = HomeScreen()

  override func viewDidLoad() {
    homeVC.animationView.pause()
    homeVC.animationTwo.pause()
    super.viewDidload()
}
 }

您不能將暫停放在當前的完成處理程序中,例如:

present(modalViewController, animated: true) {
    self.animationView.pause()
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM