呈现模态视图控制器时暂停动画
Pause animation when modal view controller is presented
我有两个动画在我的主屏幕视图控制器上播放。它们都是来自 LottieFiles 的动画。一个是 alpha 颜色变化的背景,另一个是不同颜色的无限循环。 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()
}
我有两个动画在我的主屏幕视图控制器上播放。它们都是来自 LottieFiles 的动画。一个是 alpha 颜色变化的背景,另一个是不同颜色的无限循环。 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()
}