Sean Parent
Sean Parent

Reputation: 693

hosted CALayer in NSView bounds change

I have a custom CALayer hosted in an NSView, contained in an NSScrollView, setting properties on the CALayer will cause it's bounds to change.

The problem is that the NSView really wants to own the bounds of the contained CALayer, I can make it work by adding a KVO on the bounds so when the layer bounds changes it changes the NSView bounds (which changes the layer bounds to the same value - luckily KVO doesn't recurse if the value doesn't actually change).

Is there a better way? It would seem like going through the layout system would be better but then I can only specify my preferred frame (my bounds through my transform) - and this turns into setting my bounds, but with some amount of roundoff error.

How should a CALayer request a bounds change? Or is my current hack the preferred mechanism...

Upvotes: 1

Views: 548

Answers (1)

Wil Shipley
Wil Shipley

Reputation: 9533

I’m not totally sure what you’re doing, but I’d have the CALayer set an NSSize ivar on its NSView which changes the NSView’s intrinsic size for autolayout, and then call setNeedsRelayout:YES on the view. Don’t try to have the tail wag the dog if you’re going to use a layer attached to a view.

Upvotes: 1

Related Questions