本文介绍了您可以在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);
推荐答案
基本上,它会将锚点从[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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!