【问题标题】:Can you set the anchorPoint of the root layer on an NSView?你可以在 NSView 上设置根层的锚点吗?
【发布时间】:2013-01-26 16:14:49
【问题描述】:

是否可以修改基于层的NSView 的根CALayer 上的anchorPoint 属性?

我有一个名为myView 的视图,似乎每次设置anchorPoint 时,它都会在下一个运行循环中被覆盖。我正在这样做:

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);

【问题讨论】:

    标签: macos cocoa core-animation quartz-graphics


    【解决方案1】:

    在 10.8 上,AppKit 将控制 CALayer 上的以下属性 (无论是“layer-hosted”还是“layer-backed”):geometryFlipped, bounds, 框架(隐含)、位置、锚点、变换、阴影*、隐藏、 过滤器和合成过滤器。 … 使用适当的 NSView 封面 更改这些属性的方法。

    基本上它会将锚点从 [0.5,0.5] 设置为 [0,0],为此我使用类似的东西:

    +(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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-25
      • 2011-06-16
      • 2018-08-17
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      相关资源
      最近更新 更多