Layer hosting custom NSView and setAlphaValue

  • Hello,

      I have a layer hosting custom view which I can't convince to listen to the
    alpha value I set on its superview. Other views sitting on the same superview
    correctly fade with the alpha value of the superview changing. My view doesn't.
    It simply hides when the superview's alpha is less than 1.

    Not sure what the problem is, the documentation for setAlphaValue doesn't tell
    me a lot, neither does the view programming guide.

    Any ideas?

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
  • On May 11, 2012, at 1:53 PM, Markus Spoettl <ms_lists...> wrote:

    > Hello,
    >
    > I have a layer hosting custom view which I can't convince to listen to the alpha value I set on its superview. Other views sitting on the same superview correctly fade with the alpha value of the superview changing. My view doesn't. It simply hides when the superview's alpha is less than 1.
    >
    > Not sure what the problem is, the documentation for setAlphaValue doesn't tell me a lot, neither does the view programming guide.
    >
    > Any ideas?

    Hi Markus,
    It sounds like the parent view which you are setting the alphaValue on is not layer backed, but you do apparently have a layer backed child. That won't work; make the parent layer backed.

    corbin

    >
    > Regards
    > Markus
    > --
    > __________________________________________
    > Markus Spoettl
  • On 5/14/12 6:10 PM, Corbin Dunn wrote:
    >> I have a layer hosting custom view which I can't convince to listen to the
    >> alpha value I set on its superview. Other views sitting on the same
    >> superview correctly fade with the alpha value of the superview changing. My
    >> view doesn't. It simply hides when the superview's alpha is less than 1.
    >>
    >> Not sure what the problem is, the documentation for setAlphaValue doesn't
    >> tell me a lot, neither does the view programming guide.
    >>
    >> Any ideas?
    >
    > Hi Markus, It sounds like the parent view which you are setting the
    > alphaValue on is not layer backed, but you do apparently have a layer backed
    > child. That won't work; make the parent layer backed.

    Hi Corbin, thanks and sorry for not being clearer, this is my hierarchy:

    container (NSView)
      |
      - button 1 (NSButton)
      - button 2 (NSButton)
      - Custom View (NSView subclass, layer-hosting).

    I'm setting the container's alpha value, which fades both buttons, but not my
    layer hosting custom view.

    My only guess is that there's something I need to do in my custom view but I
    have no idea what that is.

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
  • On May 14, 2012, at 9:52 AM, Markus Spoettl wrote:

    > On 5/14/12 6:10 PM, Corbin Dunn wrote:
    >>> I have a layer hosting custom view which I can't convince to listen to the
    >>> alpha value I set on its superview. Other views sitting on the same
    >>> superview correctly fade with the alpha value of the superview changing. My
    >>> view doesn't. It simply hides when the superview's alpha is less than 1.
    >>>
    >>> Not sure what the problem is, the documentation for setAlphaValue doesn't
    >>> tell me a lot, neither does the view programming guide.
    >>>
    >>> Any ideas?
    >>
    >> Hi Markus, It sounds like the parent view which you are setting the
    >> alphaValue on is not layer backed, but you do apparently have a layer backed
    >> child. That won't work; make the parent layer backed.
    >
    > Hi Corbin, thanks and sorry for not being clearer, this is my hierarchy:
    >
    > container (NSView)
    > |
    > - button 1 (NSButton)
    > - button 2 (NSButton)
    > - Custom View (NSView subclass, layer-hosting).
    >
    > I'm setting the container's alpha value, which fades both buttons, but not my layer hosting custom view.
    >
    > My only guess is that there's something I need to do in my custom view but I have no idea what that is.

    I think you need to manually animate the alpha value of your layer-hosting view's layer.

    When you're layer-hosting, AppKit doesn't muck with your layers. As long as you perform the fade of your layer-hosting view's layer within the same animation context as the animation of your superview's alpha, you should be good to go.

    I don't know whether I'd consider your scenario a bug.

    --Kyle Sluder
  • On May 14, 2012, at 9:52 AM, Markus Spoettl <ms_lists...> wrote:

    > On 5/14/12 6:10 PM, Corbin Dunn wrote:
    >>> I have a layer hosting custom view which I can't convince to listen to the
    >>> alpha value I set on its superview. Other views sitting on the same
    >>> superview correctly fade with the alpha value of the superview changing. My
    >>> view doesn't. It simply hides when the superview's alpha is less than 1.
    >>>
    >>> Not sure what the problem is, the documentation for setAlphaValue doesn't
    >>> tell me a lot, neither does the view programming guide.
    >>>
    >>> Any ideas?
    >>
    >> Hi Markus, It sounds like the parent view which you are setting the
    >> alphaValue on is not layer backed, but you do apparently have a layer backed
    >> child. That won't work; make the parent layer backed.
    >
    > Hi Corbin, thanks and sorry for not being clearer, this is my hierarchy:
    >
    > container (NSView)
    > |
    > - button 1 (NSButton)
    > - button 2 (NSButton)
    > - Custom View (NSView subclass, layer-hosting).
    >
    > I'm setting the container's alpha value, which fades both buttons, but not my layer hosting custom view.

    Hi Markus,
    That is what I thought you had as your hierarchy.

    What I was saying is that you must set your container view to be layer backed (maybe even just temporarily, while your animation is happening).

    The reason is that we use a separate CoreGraphics surface for the topmost view that hosts layers (all children views are implicitly made layer backed). Your top most view isn't layer backed, and we do a special alpha animation, which will not work with the Custom View you have made layer backed.

    corbin

    >
    > My only guess is that there's something I need to do in my custom view but I have no idea what that is.
    >
    > Regards
    > Markus
    > --
    > __________________________________________
    > Markus Spoettl
  • On May 14, 2012, at 10:49 AM, Kyle Sluder <kyle...> wrote:

    > On May 14, 2012, at 9:52 AM, Markus Spoettl wrote:
    >
    >> On 5/14/12 6:10 PM, Corbin Dunn wrote:
    >>>> I have a layer hosting custom view which I can't convince to listen to the
    >>>> alpha value I set on its superview. Other views sitting on the same
    >>>> superview correctly fade with the alpha value of the superview changing. My
    >>>> view doesn't. It simply hides when the superview's alpha is less than 1.
    >>>>
    >>>> Not sure what the problem is, the documentation for setAlphaValue doesn't
    >>>> tell me a lot, neither does the view programming guide.
    >>>>
    >>>> Any ideas?
    >>>
    >>> Hi Markus, It sounds like the parent view which you are setting the
    >>> alphaValue on is not layer backed, but you do apparently have a layer backed
    >>> child. That won't work; make the parent layer backed.
    >>
    >> Hi Corbin, thanks and sorry for not being clearer, this is my hierarchy:
    >>
    >> container (NSView)
    >> |
    >> - button 1 (NSButton)
    >> - button 2 (NSButton)
    >> - Custom View (NSView subclass, layer-hosting).
    >>
    >> I'm setting the container's alpha value, which fades both buttons, but not my layer hosting custom view.
    >>
    >> My only guess is that there's something I need to do in my custom view but I have no idea what that is.
    >
    > I think you need to manually animate the alpha value of your layer-hosting view's layer.
    >
    > When you're layer-hosting, AppKit doesn't muck with your layers. As long as you perform the fade of your layer-hosting view's layer within the same animation context as the animation of your superview's alpha, you should be good to go.
    >
    > I don't know whether I'd consider your scenario a bug.

    No, it is not a bug -- unfortunately, we can't make certain things go cross boundaries from non-layer backed to layer backed.

    This has an easy solution: layer back the container.

    corbin

    >
    > --Kyle Sluder
  • On May 14, 2012, at 11:22 AM, Corbin Dunn wrote:

    > No, it is not a bug -- unfortunately, we can't make certain things go cross boundaries from non-layer backed to layer backed.
    >
    > This has an easy solution: layer back the container.

    I assumed that Markus was already doing this, since -setAlphaValue: is documented to throw an exception if your view isn't already layer-backed.

    --Kyle Sluder
  • On 5/14/12 8:23 PM, Kyle Sluder wrote:
    > On May 14, 2012, at 11:22 AM, Corbin Dunn wrote:
    >
    >> No, it is not a bug -- unfortunately, we can't make certain things go cross
    >> boundaries from non-layer backed to layer backed.
    >>
    >> This has an easy solution: layer back the container.
    >
    > I assumed that Markus was already doing this, since -setAlphaValue: is
    > documented to throw an exception if your view isn't already layer-backed.

    I wasn't, and I was puzzled by this as well. I assumed the comment about the
    exception was a documentation left-over from earlier SDK releases. It definitely
    doesn't throw an exception when used on non-layer backed views.

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
  • On May 14, 2012, at 1:14 PM, Markus Spoettl <ms_lists...> wrote:

    > On 5/14/12 8:23 PM, Kyle Sluder wrote:
    >> On May 14, 2012, at 11:22 AM, Corbin Dunn wrote:
    >>
    >>> No, it is not a bug -- unfortunately, we can't make certain things go cross
    >>> boundaries from non-layer backed to layer backed.
    >>>
    >>> This has an easy solution: layer back the container.
    >>
    >> I assumed that Markus was already doing this, since -setAlphaValue: is
    >> documented to throw an exception if your view isn't already layer-backed.
    >
    > I wasn't, and I was puzzled by this as well. I assumed the comment about the exception was a documentation left-over from earlier SDK releases. It definitely doesn't throw an exception when used on non-layer backed views.

    Yeah, one can change the alpha value when not using layers. I guess this slipped through the cracks, as it has worked for a while. We draw the view (and children) into an image and then composite that for the real drawing.

    Definitely log a documentation bug asking to clarify this.

    corbin

    >
    > Regards
    > Markus
    > --
    > __________________________________________
    > Markus Spoettl
  • On 5/14/12 8:22 PM, Corbin Dunn wrote:
    >>> On 5/14/12 6:10 PM, Corbin Dunn wrote:
    >>>>> I have a layer hosting custom view which I can't convince to listen to the
    >>>>> alpha value I set on its superview. Other views sitting on the same
    >>>>> superview correctly fade with the alpha value of the superview changing. My
    >>>>> view doesn't. It simply hides when the superview's alpha is less than 1.
    >>>>>
    >>>>> Not sure what the problem is, the documentation for setAlphaValue doesn't
    >>>>> tell me a lot, neither does the view programming guide.
    >>>>>
    >>>>> Any ideas?
    >>>>
    >>>> Hi Markus, It sounds like the parent view which you are setting the
    >>>> alphaValue on is not layer backed, but you do apparently have a layer backed
    >>>> child. That won't work; make the parent layer backed.
    >>>
    >>> Hi Corbin, thanks and sorry for not being clearer, this is my hierarchy:
    >>>
    >>> container (NSView)
    >>> |
    >>> - button 1 (NSButton)
    >>> - button 2 (NSButton)
    >>> - Custom View (NSView subclass, layer-hosting).
    >>>
    >>> I'm setting the container's alpha value, which fades both buttons, but not my layer hosting custom view.
    >>>
    >>> My only guess is that there's something I need to do in my custom view but I have no idea what that is.
    >>
    >> I think you need to manually animate the alpha value of your layer-hosting view's layer.
    >>
    >> When you're layer-hosting, AppKit doesn't muck with your layers. As long as you perform the fade of your layer-hosting view's layer within the same animation context as the animation of your superview's alpha, you should be good to go.
    >>
    >> I don't know whether I'd consider your scenario a bug.
    >
    > No, it is not a bug -- unfortunately, we can't make certain things go cross boundaries from non-layer backed to layer backed.
    >
    > This has an easy solution: layer back the container.

    Ahh. Yes, that works beautifully, thanks! Using [NSAnimationContext
    beginGrouping/endGrouping] and the implicit animator proxy, it doesn't seem to
    work with NSViewAnimation (using NSViewAnimationFadeInEffect).

    The only side effect of this is that my custom view isn't clipped at it's bounds
    unless the root layer has -masksToBounds set to yes (which mine didn't). Easy to
    fix, interesting effect, though :)

    Thanks for the tip!

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
previous month may 2012 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 31      
Go to today