Animation Snaps back when the UIImage is changed

前端 未结 1 1786
谎友^
谎友^ 2021-01-23 21:03

I have an UIImageView that runs across the screen when a button is pressed and held. When the button is pressed is changes the UIImage of the UIImageView and when the button is

相关标签:
1条回答
  • 2021-01-23 21:39

    Core Animation uses different sets of properties to represent an object:

    From Core Animation Programming Guide:


    model layer tree (or simply “layer tree”) are the ones your app interacts with the most. The objects in this tree are the model objects that store the target values for any animations. Whenever you change the property of a layer, you use one of these objects.

    presentation tree contain the in-flight values for any running animations. Whereas the layer tree objects contain the target values for an animation, the objects in the presentation tree reflect the current values as they appear onscreen. You should never modify the objects in this tree. Instead, you use these objects to read current animation values, perhaps to create a new animation starting at those values.


    So when you animate the properties you change the presentation layer, but once the animation is finished the object reverts back to its model property values.

    What you need to do to fix this is use the [CAAnimation animationDidStop:finished:] delegate method to set the final property value and anything else you would like to do. I think you could use this to dump that horrible NSTimer code you are using and one small part of the world will be that much better.

    0 讨论(0)
提交回复
热议问题