UIView的属性层不是只读的吗? [英] Isn't property layer of UIView be readonly?

查看:71
本文介绍了UIView的属性层不是只读的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIView的属性层在Apple的文档中描述如下:

The property layer of UIView is described in Apple's doc as following:

图层

用于渲染的视图的核心动画"层. (只读)

The view’s Core Animation layer used for rendering. (read-only)

@property(nonatomic, readonly, retain) CALayer *layer

很明显,它是只读的.但是在我的项目中,为什么可以将其设置如下:

It is obviously that it is readonly. But in my project, why it could be set as following:

NSLog(@"before: %f",self.myView.laye.frame.size.width);
[self.myView.layer setAffineTransform:CGAffineTransformMakeScale(2, 2)];
NSLog(@"after: %f",self.myView.laye.frame.size.width);
//log shows us that the frame is modified 

在这种情况下真的很困惑.有人可以帮我吗?预先感谢!

Really confused in this situation. Anyone can help me out? Thanks in advance!

推荐答案

layer属性是只读的,这意味着您不能将图层更改为另一个图层,但是该属性中包含的CALayer对象不是不可变的,您可以设置自己的属性.

The layer property is read-only, it means you cannot change the layer for another, however the CALayer object contained in the property is not immutable, you can set its own properties.

您不能这样做:

self.myView.layer = newLayer;
// equivalent to [self.myView setLayer:newLayer];

但是您可以这样做:

[self.myView.layer setAffineTransform:CGAffineTransformMakeScale(2, 2)];

这是您无法使用的setLayer:选择器.

It's the setLayer: selector that you can't use.

这篇关于UIView的属性层不是只读的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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