在NSView层上设置仿射变换不像在iOS上那样工作

时间:2023-02-09 11:57:02

I am trying to achieve something very simple. I would like to transform a layer's scale. However it does not seem to work as expected. In fact, it does not work at all. The layer's scale remains the same.

我想要实现一些非常简单的事情。我想改变一个层的规模。但它似乎没有按预期工作。事实上,它根本不起作用。图层的比例保持不变。

Here is my code:

这是我的代码:

NSView *v = [[NSView alloc]init];
v.wantsLayer = YES;
v.frame = self.bounds;
float scale = 0.8f;
[v.layer setAffineTransform:CGAffineTransformMakeScale(scale,scale)];
[self addSubview:v];

If I log the affineTransform property of v I get null.

如果我记录v的affineTransform属性,则得到null。

1 个解决方案

#1


6  

Try this on OSX:

在OSX上试试这个:

self.layer.sublayerTransform = CATransform3DMakeScale(scale, scale, 0.0f);

#1


6  

Try this on OSX:

在OSX上试试这个:

self.layer.sublayerTransform = CATransform3DMakeScale(scale, scale, 0.0f);