Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get a position (or center) state from a unfinished UIView animation?

I have a UIView doing a simple animation. It adjusts its y position from 100 to 130 and then reverses. I want it to keep repeating so I have the repeat counter set to 999. Upon user input, I want to take the same UIView and adjust the x position. This is done by means of another UIView animation. The problem is that when the 2nd animation starts, the 1st animation (that goes from 100 to 130 in the y direction) just ends abruptly (as I read that it should). Is there any way to get the final position of the y coordinate of that UIView before it was ended? I would ideally like to have the UIView stay in the same y position that it was in while I translate the x coordinates.

Summary: UIView moves in the y direction from 100-130, reverses and repeats until user input is received. Once received, animation is cut short and UIView jumps to y=130. I would like a way to find out what the final y value was before the animation was cut short, so when new animation with x translation is used, the UIView will not jump to 130, but remain the same position it was in when the 1st animation ended.

I can't seem to see anything that would let you do that. It appears to me that once you set the animation in motion with UIView, then it (and all current state changes) are out of your hands and will only be "returned" to your control and availability once the animation is done and at the designated end point. Is this correct? Any insight would be appreciated. Thank you for your time.

like image 266
MarcZero Avatar asked Jan 22 '23 16:01

MarcZero


1 Answers

You're looking for the "presentation layer".

Each UIView is rendered using a Core Animation layer, which is accessible from UIView's layer property.

CALayer has a presentationLayer method, which returns a CALayer that represents "a close approximation to the version of the layer that is currently being displayed".

So, to get the current position of your view:

CGRect currentViewFrame = [[myView.layer presentationLayer] frame];
like image 170
Darren Avatar answered Jan 30 '23 02:01

Darren