gpt4 book ai didi

macos - 你能在NSView上设置根层的anchorPoint吗?

转载 作者:行者123 更新时间:2023-12-03 16:20:21 25 4
gpt4 key购买 nike

是否可以修改图层支持的 NSViewCALayer 上的 anchorPoint 属性?

我有一个名为 myView 的 View ,似乎每次我设置 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);

最佳答案

On 10.8, AppKit will control the following properties on a CALayer (both when "layer-hosted" or "layer-backed"): geometryFlipped, bounds, frame (implied), position, anchorPoint, transform, shadow*, hidden, filters, and compositingFilter. … Use the appropriate NSView cover methods to change these properties.

基本上,它将把 anchor 设置为 [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);
}

关于macos - 你能在NSView上设置根层的anchorPoint吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14814212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com