这是来自my PageController的第一个子视图类
的viewDidAppear override func viewDidAppear(_ animated: Bool) {
print("hello")
self.view.layoutIfNeeded()
self.averageWorkSessions.shapeLayer.strokeEnd = 0
UIView.animate(withDuration: 0.5) {
let average = CGFloat(self.averageWorkSessions.average / 10)
self.averageWorkSessions.shapeLayer.strokeEnd = average
if !(average > 0.0){
self.averageWorkSessions.Title.text = "N/A"
}
self.view.layoutIfNeeded()
}
}
考虑一下
averageWorkSessions是一个包含自定义组件的自定义视图,但它仍然是UIView的子类
以下是页面控制器的一部分,无论如何都可能与此问题有关
lazy var subViewControllers: [UIViewController] = {
return [
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Stats1") as! StatisticsViewController ,
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Stats2") as! Statistics2ViewController ,
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Stats3") as! Statistics3ViewController
]
}()
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
self.dataSource = self
setViewControllers([subViewControllers[0]], direction: .forward , animated: true, completion: nil)
self.view.layoutIfNeeded()
}
简短版
为什么这不能正常动画?打印“你好”的工作原理与预期完全一样......为什么不是我的动画呢?
答案 0 :(得分:2)
我认为问题在于您在self.averageWorkSessions.shapeLayer.strokeEnd
UIView.animate()
self.view.layoutIfNeeded()
应位于UIView.animate()
内,但不应设置常量。