gpt4 book ai didi

ios - 由于 UIView.animate 和 UIView.animateKeyframes 导致 CPU 使用率高

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:33:00 45 4
gpt4 key购买 nike

我有两个 View Controller 。 AnimationVC 有一些 UIView 动画,而 DestinationVC 没有。

我有 CPU 使用问题。在我执行 segue 之后,动画 block 仍然显示在 Instruments 中,即使这些行属于执行 segue 的 AnimationVC

   UIView.animate(withDuration: 1.0, delay: 0.0, options: [.curveEaseInOut, .autoreverse, .repeat], animations: {
self.s1.alpha = 0.0
self.s3.alpha = 0.0
}, completion: nil)

    let dur = 0.5/12
UIView.animateKeyframes(withDuration: 30.0, delay: 0.0, options: [.repeat, .calculationModeCubic], animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: dur, animations: {
self.sc.alpha = 1.0
})

UIView.addKeyframe(withRelativeStartTime: 1.0-dur, relativeDuration: dur, animations: {
self.sc.alpha = 0.0
})

UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 1.0, animations: {
self.sc.transform = CGAffineTransform(rotationAngle: .pi*0.2)
})

UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 1.0, animations: {
self.sc.center.y = 0.1*self.frame.size.height
})
}, completion: nil)

我试过调用这个 destruct 函数...

func destruct(){
layer.removeAllAnimations()
subviews.forEach { $0.removeFromSuperview() }
}

...在

  1. 就在执行转场之前
  2. AnimationVC的deinit方法中

仍然,它显示为 alive 并以 40% 的负载占用 CPU。我怎样才能破坏它?我什至重置了 DestinationVC 上的导航堆栈...

self.navigationController?.viewControllers = [self]

...我看到 AnimationVC 中的 deinit 行,动画延迟关闭仍然有效。

From Instruments

最佳答案

事实证明

   ...
}) { (finished) in
if finished {
self.specialAniamtion(delay: 2.0)
}
}

并在 deinit 上调用 destruct() 修复了它。

func destruct(){
layer.removeAllAnimations()
}

关于ios - 由于 UIView.animate 和 UIView.animateKeyframes 导致 CPU 使用率高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44152138/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com