CALayer vs Layer Backed Views

  • Hi list,

    I'm playing around with layers and there are some subtleties I don't
    quite get when using layer backed views. I did some animations using
    "pure" CALayers as a proof of concept for a view. Along the way I
    figured I'd like to have subviews (NSViews) embedded in it and so I
    went back to do everything using NSViews that have setWantsLayer set
    to yes.

    I noticed that if I change the zPosition of the view's layer it does
    not animate while it used to when using CALayers only. The position
    changes correctly, I'm only missing the animation. Changing the view's
    frame using the animator works fine. I'm wondering, is it safe to
    change attributes of the layer when the view is in layer backed mode?
    If it is not safe, is there a way to change transform of the view ?

    Thanks.
  • I have set a perspective transform, when I did not the zPosition did
    not have any effect.

    Just to be clearer, I see the transform applied correctly, I just
    don't get the animation of that property of the layer.

    I've had some answer off list that we should expect more details soon
    of what we can and can't do with the layer of a view.

    2007/11/1, Andre <son_gohan...>:
    > Have you set a perspective transform on the CA3DTransform3D value of
    > the enclosing layer? (The layer that encloses all your sublayers)
    > If you don't set a perspective transform, then z-position changes
    > won't animate.....
    > Also, what are the values you are setting for the Z-position?
    > Sometimes setting the z-position to some outrageous number causes
    > trouble..... (I haven't tested with 9A581)
    >
    > I've noticed some oddities with CALayer backed NSViews.... basically 3-
    > d rotation and stuff is a bit wonky.... at least in the betas it
    > was.... hit detection doesn't work in 3-d for example....
    > Moving in 2-d space though should be fine...
    >
    > Andre
    >
    > On $BJ?@.(B 19/11/01, at 18:56, Bertrand Landry-Hetu wrote:
    >
    >> Hi list,
    >>
    >> I'm playing around with layers and there are some subtleties I don't
    >> quite get when using layer backed views. I did some animations using
    >> "pure" CALayers as a proof of concept for a view. Along the way I
    >> figured I'd like to have subviews (NSViews) embedded in it and so I
    >> went back to do everything using NSViews that have setWantsLayer set
    >> to yes.
    >>
    >> I noticed that if I change the zPosition of the view's layer it does
    >> not animate while it used to when using CALayers only. The position
    >> changes correctly, I'm only missing the animation. Changing the view's
    >> frame using the animator works fine. I'm wondering, is it safe to
    >> change attributes of the layer when the view is in layer backed mode?
    >> If it is not safe, is there a way to change transform of the view ?
    >>
    >> Thanks.
    >
    >
  • Thats interesting, because I have got it to work.

    I threw something together real quick...
    Basically, I have a layer backed container view, a pre-existing view
    in the nib, and an action on the controller that inserts the view into
    the container that is layer backed.
    Just to be sure, it explicitly set the layer of the inserted view to a
    layer (new or pre-existing), and it works.
    I have my layer hierarchy maintained by an (don't yell at me please)
    NSArrayControler, so I can confirm that when I set the selected layer,
    and attach that selected layer to a view, it all works....
    Z-position, Z-rotation, everything........ except scaling and resizing
    and positioning (e.g resizing the layer will not resize the view and
    positioning the layer in X/Y will not re-position the view)
    That being said, scaling and rotating the sublayer transform of the
    super layer (container) will scale and rotate the etc the view......
    so a workaround may be, for every view:

    Have it layer backed, insert the view as a subview of another view
    that is layer backed.
    Apply scaling, z-ordering, rotation on the **superview's** sublayer
    transform.
    IOW, use a container view for every view that you insert and operate
    on its sublayerTransform........

    Ahh, I think I got it. Instead of the above, try to operate on just
    the sublayer transform of the layer backed view first..... see what
    happens.

    Andre

    On $BJ?@.(B 19/11/02, at 6:07, Bertrand Landry-Hetu wrote:

    > I have set a perspective transform, when I did not the zPosition did
    > not have any effect.
    >
    > Just to be clearer, I see the transform applied correctly, I just
    > don't get the animation of that property of the layer.
    >
    > I've had some answer off list that we should expect more details soon
    > of what we can and can't do with the layer of a view.
    >
    > 2007/11/1, Andre <son_gohan...>:
    >> Have you set a perspective transform on the CA3DTransform3D value of
    >> the enclosing layer? (The layer that encloses all your sublayers)
    >> If you don't set a perspective transform, then z-position changes
    >> won't animate.....
    >> Also, what are the values you are setting for the Z-position?
    >> Sometimes setting the z-position to some outrageous number causes
    >> trouble..... (I haven't tested with 9A581)
    >>
    >> I've noticed some oddities with CALayer backed NSViews....
    >> basically 3-
    >> d rotation and stuff is a bit wonky.... at least in the betas it
    >> was.... hit detection doesn't work in 3-d for example....
    >> Moving in 2-d space though should be fine...
    >>
    >> Andre
    >>
    >> On $BJ?@.(B 19/11/01, at 18:56, Bertrand Landry-Hetu wrote:
    >>
    >>> Hi list,
    >>>
    >>> I'm playing around with layers and there are some subtleties I don't
    >>> quite get when using layer backed views. I did some animations using
    >>> "pure" CALayers as a proof of concept for a view. Along the way I
    >>> figured I'd like to have subviews (NSViews) embedded in it and so I
    >>> went back to do everything using NSViews that have setWantsLayer set
    >>> to yes.
    >>>
    >>> I noticed that if I change the zPosition of the view's layer it does
    >>> not animate while it used to when using CALayers only. The position
    >>> changes correctly, I'm only missing the animation. Changing the
    >>> view's
    >>> frame using the animator works fine. I'm wondering, is it safe to
    >>> change attributes of the layer when the view is in layer backed
    >>> mode?
    >>> If it is not safe, is there a way to change transform of the view ?
    >>>
    >>> Thanks.
    >>
    >>

  • I have pretty much the same hierarchy except I'm not replacing the
    builtin layer.

    Anything I do using the "animator" works fine. Only the attributes I
    change directly on the layer are not getting animated. There must be
    some setup I'm missing for core animation to kick in.

    I have a hunch that I need to set a layoutManager on the base view.
    layoutSublayersOfLayer: might have the required setup.

    I think I'll go full CALayer, but I'm stubborn and I like to
    understand how things work :).

    2007/11/1, <listposter...> <listposter...>:
    > Thats interesting, because I have got it to work.
    >
    > I threw something together real quick...
    > Basically, I have a layer backed container view, a pre-existing view
    > in the nib, and an action on the controller that inserts the view into
    > the container that is layer backed.
    > Just to be sure, it explicitly set the layer of the inserted view to a
    > layer (new or pre-existing), and it works.
    > I have my layer hierarchy maintained by an (don't yell at me please)
    > NSArrayControler, so I can confirm that when I set the selected layer,
    > and attach that selected layer to a view, it all works....
    > Z-position, Z-rotation, everything........ except scaling and resizing
    > and positioning (e.g resizing the layer will not resize the view and
    > positioning the layer in X/Y will not re-position the view)
    > That being said, scaling and rotating the sublayer transform of the
    > super layer (container) will scale and rotate the etc the view......
    > so a workaround may be, for every view:
    >
    > Have it layer backed, insert the view as a subview of another view
    > that is layer backed.
    > Apply scaling, z-ordering, rotation on the **superview's** sublayer
    > transform.
    > IOW, use a container view for every view that you insert and operate
    > on its sublayerTransform........
    >
    > Ahh, I think I got it. Instead of the above, try to operate on just
    > the sublayer transform of the layer backed view first..... see what
    > happens.
    >
    > Andre
    >
    > On $BJ?@.(B 19/11/02, at 6:07, Bertrand Landry-Hetu wrote:
    >
    >> I have set a perspective transform, when I did not the zPosition did
    >> not have any effect.
    >>
    >> Just to be clearer, I see the transform applied correctly, I just
    >> don't get the animation of that property of the layer.
    >>
    >> I've had some answer off list that we should expect more details soon
    >> of what we can and can't do with the layer of a view.
    >>
    >> 2007/11/1, Andre <son_gohan...>:
    >>> Have you set a perspective transform on the CA3DTransform3D value of
    >>> the enclosing layer? (The layer that encloses all your sublayers)
    >>> If you don't set a perspective transform, then z-position changes
    >>> won't animate.....
    >>> Also, what are the values you are setting for the Z-position?
    >>> Sometimes setting the z-position to some outrageous number causes
    >>> trouble..... (I haven't tested with 9A581)
    >>>
    >>> I've noticed some oddities with CALayer backed NSViews....
    >>> basically 3-
    >>> d rotation and stuff is a bit wonky.... at least in the betas it
    >>> was.... hit detection doesn't work in 3-d for example....
    >>> Moving in 2-d space though should be fine...
    >>>
    >>> Andre
    >>>
    >>> On $BJ?@.(B 19/11/01, at 18:56, Bertrand Landry-Hetu wrote:
    >>>
    >>>> Hi list,
    >>>>
    >>>> I'm playing around with layers and there are some subtleties I don't
    >>>> quite get when using layer backed views. I did some animations using
    >>>> "pure" CALayers as a proof of concept for a view. Along the way I
    >>>> figured I'd like to have subviews (NSViews) embedded in it and so I
    >>>> went back to do everything using NSViews that have setWantsLayer set
    >>>> to yes.
    >>>>
    >>>> I noticed that if I change the zPosition of the view's layer it does
    >>>> not animate while it used to when using CALayers only. The position
    >>>> changes correctly, I'm only missing the animation. Changing the
    >>>> view's
    >>>> frame using the animator works fine. I'm wondering, is it safe to
    >>>> change attributes of the layer when the view is in layer backed
    >>>> mode?
    >>>> If it is not safe, is there a way to change transform of the view ?
    >>>>
    >>>> Thanks.
    >>>
    >>>

    >
    >
  • I tried it and layoutSublayersOfLayer: gets the animation working. So
    CALayers needs something the layout system does. At this point its
    probably a question meant to the Quartz mailing list.

    2007/11/1, Bertrand Landry-Hetu <bertrandl...>:
    > I have pretty much the same hierarchy except I'm not replacing the
    > builtin layer.
    >
    > Anything I do using the "animator" works fine. Only the attributes I
    > change directly on the layer are not getting animated. There must be
    > some setup I'm missing for core animation to kick in.
    >
    > I have a hunch that I need to set a layoutManager on the base view.
    > layoutSublayersOfLayer: might have the required setup.
    >
    > I think I'll go full CALayer, but I'm stubborn and I like to
    > understand how things work :).
previous month november 2007 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