Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa CALayer、锚点和图层层次_Cocoa_Macos_Core Animation_Hierarchy_Calayer - Fatal编程技术网

Cocoa CALayer、锚点和图层层次

Cocoa CALayer、锚点和图层层次,cocoa,macos,core-animation,hierarchy,calayer,Cocoa,Macos,Core Animation,Hierarchy,Calayer,我尝试使用层层次中的锚点来移动层及其子层。不幸的是,子层没有与根层一起移动。在自定义NSView中,设置我的图层层次结构,如以下代码段所示 CALayer * rootLayer; rootLayer = [[CALayer layer] retain]; rootLayer.position = CGPointMake(...); [self.layer addSublayer:rootLayer]; subLayer = [[MapLayer layer] retain]; subLaye

我尝试使用层层次中的锚点来移动层及其子层。不幸的是,子层没有与根层一起移动。在自定义NSView中,设置我的图层层次结构,如以下代码段所示

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

subLayer = [[MapLayer layer] retain];
subLayer.position = CGPointMake(...);
[rootLayer addSublayer:baseLayer];
在处理鼠标事件时,我想设置根层的锚点以移动整个层层次结构:

rootLayer.anchorPoint = CGPoint(0.7, 0.7);
我期望通过这个调用,根层与其子层一起移动,以便锚定点位于视图的中心。发生的情况是,子层没有移动。只有当我打电话时:

rootLayer.anchorPoint = CGPoint(0.7, 0.7);
subLayer.anchorPoint = CGPoint(0.7, 0.7);
层的行为符合预期

我认为设置根层的锚点就足够了。这在我的OSX应用程序中使用。在那里,我设置了视图,并使用锚点移动整个地图。在自定义NSView中只有一个子层,应用程序的行为符合预期

提前谢谢

更新:与同事讨论后,我设置了根层的边界,现在它可以工作了

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

// ...

您应该添加更新作为答案并接受它。