Re: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)

2012-02-09 Thread Kyle Sluder
On Thu, Feb 9, 2012 at 11:09 AM, Fritz Anderson fri...@manoverboard.org wrote:
 * Create a duplicate CAShapeLayer (maskL) with [[CAShapeLayer alloc] 
 initWithLayer: shapeL].
        - Adjust the fill color to blackColor, because masking goes by alpha.

The CALayer documentation makes it quite clear that you should never,
ever do this:

Note: Invoking this method in any other situation will produce
undefined behavior. Do not use this method to initialize a new layer
with an existing layer’s content.

https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html

--Kyle Sluder

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)

2012-02-09 Thread David Duncan
On Feb 9, 2012, at 11:09 AM, Fritz Anderson wrote:

 The trick was that -initWithLayer: did not produce a usable mask layer.

Applications should not call -initWithLayer:. Its purpose of existence is so 
that if you have a CALayer subclass that has additional ivars that need 
copying, you can implement it and CoreAnimation can call it to do the right 
thing. The layers produced in this way are not expected to be useful as 'model' 
layers.

 If I created maskL as a new mask layer ([CAShapeLayer layer]), and 
 initialized it to match shapeL (except for the fill), gradL was drawn as 
 expected.
 
 http://stackoverflow.com/questions/4733966/applying-a-gradient-to-cashapelayer
  got me most of the way, but didn't extend to how to re-use the mask layer.

Did you add the stroke shape layer as a sublayer of the gradient layer? If so, 
that may explain why you didn't get your stroke – the mask applies to a layer 
and all of its sublayers. As such, the shape layer would have at least 
partially masked the stroke (its possible Core Animation simply rejected 
rendering the shape layer entirely, as its path rendering emphasizes speed over 
accuracy).

--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)

2012-02-09 Thread Fritz Anderson
On 9 Feb 2012, at 1:25 PM, Kyle Sluder wrote:

 The CALayer documentation makes it quite clear that you should never,
 ever do this:

Hence the last word of the subject of this thread.

— F


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)

2012-02-09 Thread David Duncan
On Feb 9, 2012, at 1:37 PM, Fritz Anderson wrote:

 On 9 Feb 2012, at 1:25 PM, Kyle Sluder wrote:
 
 The CALayer documentation makes it quite clear that you should never,
 ever do this:
 
 Hence the last word of the subject of this thread.


Perhaps, but I believe that our point is that -initWithLayer: is not a method 
to use to duplicate a layer, its a method to create a shadow layer (which is 
something strictly for Core Animation's usage). If you duplicated a layer (by 
calling -init and setting all the appropriate properties) then there is no 
reason why it shouldn't work.
--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)

2012-02-09 Thread Fritz Anderson
On 9 Feb 2012, at 4:30 PM, David Duncan wrote:

 Perhaps, but I believe that our point is that -initWithLayer: is not a method 
 to use to duplicate a layer, its a method to create a shadow layer (which is 
 something strictly for Core Animation's usage). If you duplicated a layer (by 
 calling -init and setting all the appropriate properties) then there is no 
 reason why it shouldn't work.

Absolutely.

On 9 Feb 2012, at 1:09 PM, Fritz Anderson wrote:

 The trick was that -initWithLayer: did not produce a usable mask layer. If I 
 created maskL as a new mask layer ([CAShapeLayer layer]), and initialized it 
 to match shapeL (except for the fill), gradL was drawn as expected.

I assume this is what you just said — or are you getting at a different way to 
duplicate the layer?

— F


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Clipping a CAGradientLayer with a duplicated CAShapeLayer (don't)

2012-02-09 Thread David Duncan
On Feb 9, 2012, at 2:36 PM, Fritz Anderson wrote:

 On 9 Feb 2012, at 1:09 PM, Fritz Anderson wrote:
 
 The trick was that -initWithLayer: did not produce a usable mask layer. If I 
 created maskL as a new mask layer ([CAShapeLayer layer]), and initialized it 
 to match shapeL (except for the fill), gradL was drawn as expected.
 
 I assume this is what you just said — or are you getting at a different way 
 to duplicate the layer?


Nope, using +layer or -init and copying appropriate properties is an 
appropriately acceptable way to duplicate a layer. 
--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com