CALayer, anchorPoint, and level hierarchy

I am trying to use anchorPoint in a layer hierarchy to move a layer with its sublayers. Unfortunately, the sublayer did not move along with the root layer. The custom NSView has a level hierarchy configured, as in the following snippet.

CALayer * rootLayer;
rootLayer = [[CALayer layer] retain];
rootLayer.position = CGPointMake(...);
[self.layer addSublayer:rootLayer];

subLayer = [[MapLayer layer] retain];
subLayer.position = CGPointMake(...);
[rootLayer addSublayer:baseLayer];

During the processing of the mouse event, I want to set the anchorPoint of the root layer to move the entire hierarchy of layers:

rootLayer.anchorPoint = CGPoint(0.7, 0.7);

I expect from this call that rootLayer moves with its sublayer so that the anchor point is in the center of the view. It happens that the sublevel did not move. Only when I call:

rootLayer.anchorPoint = CGPoint(0.7, 0.7);
subLayer.anchorPoint = CGPoint(0.7, 0.7);

layers behave as expected.

, . Map OS X. anchorPoint . NSView .

.

UPDATE. .

CALayer * rootLayer;
rootLayer = [[CALayer layer] retain];
rootLayer.bounds = CGRectMake(0, 0, 256, 256);
rootLayer.position = CGPointMake(...);
[self.layer addSublayer:rootLayer];

// ...
+3

Source: https://habr.com/ru/post/1755312/


All Articles