CALayer -displayLayer:inContext: never called during frame/bounds animation

  • Hi guys,
    I need to animate the frame of a CALayer instance; during the animation I should also update/redraw the content of the layer based upon the new size (frame by frame) of it.

    I've tried to watch and use -displayLayer:inContext: of CALayer (it's a delegate property) but It does not work: both with frame (it's a derived property of bounds/location/anchorPoint) and bounds animation I can't receive this message (it should be called by CALayer's internal drawInContext: method) during the animation process.

    Using needsDisplayOnBoundsChange I can get it called at the end of the animation, but nothing with bounds.
    It works fine with custom properties (I need to return YES on needsDisplayForKey method).

    Any idea?
    Is possible to force redraw of CALayer contents during bounds/frame animation?
  • On Jun 8, 2013, at 6:04 AM, Daniele Margutti <ml...> wrote:

    > Hi guys,
    > I need to animate the frame of a CALayer instance; during the animation I should also update/redraw the content of the layer based upon the new size (frame by frame) of it.
    >
    > I've tried to watch and use -displayLayer:inContext: of CALayer (it's a delegate property) but It does not work: both with frame (it's a derived property of bounds/location/anchorPoint) and bounds animation I can't receive this message (it should be called by CALayer's internal drawInContext: method) during the animation process.
    >
    > Using needsDisplayOnBoundsChange I can get it called at the end of the animation, but nothing with bounds.
    > It works fine with custom properties (I need to return YES on needsDisplayForKey method).
    >
    > Any idea?

    The behavior you see is correct. Remember that the model layer (the layer you have) only sees discrete values for an animation – typically the beginning and end values. The intermediate values are generated by the Core Animation for rendering and you are not called back for them.

    As such needsDisplayOnBoundsChange will only cause the layer to display once when the bounds changes, and you will only get -drawLayer:inContext: called once as a result.

    > Is possible to force redraw of CALayer contents during bounds/frame animation?

    What kind of animation are you trying to produce? There are a few different ways you could do this, but you may run into performance problems from all the redrawing first.
    --
    David Duncan
  • On 10 Jun 2013, at 16:50, David Duncan <david.duncan...> wrote:

    > The behavior you see is correct. Remember that the model layer (the layer you have) only sees discrete values for an animation – typically the beginning and end values. The intermediate values are generated by the Core Animation for rendering and you are not called back for them.
    >
    > As such needsDisplayOnBoundsChange will only cause the layer to display once when the bounds changes, and you will only get -drawLayer:inContext: called once as a result.
    >
    >> Is possible to force redraw of CALayer contents during bounds/frame animation?
    >
    > What kind of animation are you trying to produce? There are a few different ways you could do this, but you may run into performance problems from all the redrawing first

    Suppose you need to draw an image inside the CALayer and adjust them when bounds of the layer changes. If displayLayer is called at the start and at the end during the animation my image is not update and draws is wrong, so I need to update draw inside as like happens with NSView’s/UIView’s drawRect: method.
previous month june 2013 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today