My presentation layer does not match my model layer even though I have no animations

此生再无相见时 提交于 2019-12-10 18:55:42

问题


On iPhone I have a CALayer that I animate via Core Animation. Then at some point I change view controllers. I then return to the view controller with the CALayer and in viewWillAppear: I set the frame and position properties on my layer to move it back to its starting point.

Setting these properties changes the model layer but the presentation layer still has the old values and its presentation layer does not update until the next animation I play.

In the CA Programming guide it says :

"You can query an instance of CALayer for its corresponding presentation layer while an animation transaction is in process."

Which, to me, implies that the presentation layer should only be different from the model layer during an animation. But there are no animations currently running. I even used kCATransactionDisableActions to ensure that when I set the position property an implicit animation is not started.

Does anyone know why my presentation and model layers are out of sync?

Thanks.


回答1:


One workaround I've used is to reset the position of my layers in viewWillDisappear. Also I noticed that if I don't animate my layer right away then it does indeed move to the position that I set in viewWillAppear.




回答2:


It sounds like Apple just uses the Presentation Layer during animations, and has lazy updates to it. When it's not animating, it must use the normal layer. My only bet is this is how they manage to thread the UI and avoid weird errors. It may even be related to which threads are used.

Your problem gives us insight into Apple's hood, perhaps the answer is simply that is what apple is choosing, and it answers a question I had, too.



来源:https://stackoverflow.com/questions/2578646/my-presentation-layer-does-not-match-my-model-layer-even-though-i-have-no-animat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!