Can you set the anchorPoint of the root layer on an NSView?

风格不统一 提交于 2019-12-21 05:43:04

问题


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

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

回答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.

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


来源:https://stackoverflow.com/questions/14814212/can-you-set-the-anchorpoint-of-the-root-layer-on-an-nsview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!