您可以在NSView上设置根层的anchorPoint吗? [英] Can you set the anchorPoint of the root layer on an NSView?

查看:175
本文介绍了您可以在NSView上设置根层的anchorPoint吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to modify the anchorPoint property on the root CALayer of a layer-backed NSView?

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

I have a view called myView and it seems every time I set the anchorPoint, it gets overridden in the next run loop. I am doing this:

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

推荐答案

在10.8版中,AppKit将控制CALayer上的以下属性 (无论是层托管"还是层支持"):geometryFlipped,界限, 框架(暗示),位置,anchorPoint,变换,阴影*,隐藏, 过滤器和compositingFilter. …使用适当的NSView护盖 更改这些属性的方法.

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.

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

Basically it will set the anchor to [0,0] from [0.5,0.5], to account for this i uses 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);
}

这篇关于您可以在NSView上设置根层的anchorPoint吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆