Observing Change in Frame of a Uiview During Animation

How to get UIView frame origin and size while animation

I'm pretty sure that it's not possible, because when you change the frame of your view it takes effect immediately. In the background, Core Animation takes care of the animation. So, even if you could grab the frame, it'd give you the final coordinates, not the current coordinates in the midst of an animation.

Access the presentation layer of the property, as pointed out by NWCoder in the comments. See the documentation.

[view.layer.presentationLayer frame]

How do I redraw a UIView's sublayers as I'm animating the UIView's bounds?

Layers don't work like views. If you call setNeedsDisplay (which happends if you have set needsDisplayOnBoundsChange to YES) on the parent layer it will not affect the child layers. You need to call setNeedsDisplay them as well.

If your sublayers need to be resized as well when the parent layer is resized then implement layoutSublayers in the parent (or layoutSublayersOfLayer: in its delegate).

Key value Observing during UIView Animations

You can retrieve the values representing the current state of the UIView's animating layer by accessing its presentation layer. This can be done using code like the following:

CGPoint currentCenter = [[view.layer presentationLayer] center];

Unfortunately, the presentation layer's properties are not KVO-compliant, so the best way I can think of for tracking the current value is to keep polling the presentation layer until it gets near the location you want.



Related Topics



Leave a reply



Submit