Re: Confusing CALayer Transform/Frame/Bounds Behavior
Re: Confusing CALayer Transform/Frame/Bounds Behavior
- Subject: Re: Confusing CALayer Transform/Frame/Bounds Behavior
- From: Seth Willits <email@hidden>
- Date: Wed, 25 Jan 2012 13:23:07 -0800
Another thing I've noticed when a transform is applied, is that convertPoint:toLayer: and hitTest: don't seem to agree. I have a root layer in an NSView, a "parent" sublayer of root with a (scaling) transform applied, and many sublayers of that parent layer.
If I click on a sublayer and use that mouse point in a hit test [root hitTest:p]; I get the correct sublayer back. But I noticed that if I do: [parent hitTest:[root convertPoint:p toLayer:parent]], then I don't. It seems that while convertPoint:toLayer: accounts for the transform and scales the point according to the transform, hitTest: does not want a scaled point.
To put it in concrete terms, I'll make up a scenario. Imagine a tic-tac-toe arrangement of nine 100x100 "tile" layers as sublayers of a "board" layer, which is a sublayer of the NSView's root layer. So for 1-to-1 the view should be 300x300 points. Now say I resize this view to 150x150, and set the board layer's transform to scale X and Y by 0.5. So now everything just is scaled down by half. If I click at {75, 75}, I'm visually clicking on the center tile on the board. With [root hitTest:{75, 75}], it would return that tile. But [root convertPoint:{75, 75} toLayer:board] returns {150, 150}, and [board hitTest:{150, 150}] will return the center tile in the top row, not the middle row.
Curious as to what the explanation here is. If I wanted to ignore a whole branch of layers in the tree, I may way to direct the hitTest direct at a specific sublayer of the view's root layer, but there's some "gotcha" I'm not aware of. I've read all of the documentation and done a bunch of searching, but I can't find an explanation.
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden