我有两个动画在我的主屏幕 View Controller 上播放。它们都是来自 LottieFiles 的动画。一个是 alpha 颜色变化的背景,另一个是不同颜色的无限循环。当选择当前上下文上的新模态视图时,我想暂停两个动画,并在模态视图关闭后再次启动它们。
我尝试调用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()
}
关于ios - 呈现模态视图 Controller 时暂停动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58516823/