Can you set root layer anchor in NSView?
Is it possible to change a property anchorPoint
in the root CALayer
supported by a layer NSView
?
I have a view called myView
and it seems that every time I install anchorPoint
it is overridden in the next startup loop. I'm doing it:
NSView *myView = [[myView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
//set the root layer
myView.layer = [CALayer layer];
myView.wantsLayer = YES;
//gets overridden on the next run loop
myView.layer.anchorPoint = CGPointMake(1,1);
source to share
In 10.8, AppKit will manage the following properties on the CALayer (in both "layer placement" and "layer" style): geometryFlipped, bounds, frame (implied), position, anchor, transform, shadow *, hidden, filters and compositingFilter .... Use the appropriate NSView cover methods to change these properties.
Basically it will set the anchor to [0,0] from [0,5,0,5], to account for this, I use something like:
+(void) accountForLowerLeftAnchor:(CALayer*)layer
{
CGRect frame = layer.frame;
CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));
layer.position = center;
layer.anchorPoint = CGPointMake(0.5, 0.5);
}
source to share