简体   繁体   English

CALayer:在图层内容上维护cornerRadius

[英]CALayer: Maintaining cornerRadius on layer's contents

I've been looking at the CALayer's documentation and it seems like cornerRadius only affects the background of the layer and not the contents . 我一直在查看CALayer的文档 ,看起来cornerRadius只影响图层的背景而不影响contents

Is there a way to apply the corner radius to the entire CALayer without taking a big performance hit? 有没有办法将角半径应用到整个CALayer而不会影响性能?

I've seen suggestions about masks, but that sounds costly. 我看过有关面具的建议,但这听起来很昂贵。 I've also seen suggestions about drawing the contents manually, but I don't really know where to start. 我也看到了关于手动绘制contents建议,但我真的不知道从哪里开始。 I know a bit about rendering images in contexts, but I don't know how I'm supposed to draw it onto the CALayer 's content view with a corner radius. 我对在上下文中渲染图像有点了解,但我不知道我应该如何将它绘制到具有圆角半径的CALayer内容视图上。 The best I would know is to subclass CALayer and override the drawInContext method and use CGContextDrawImage . 我要知道的最好的是子类CALayer并覆盖drawInContext方法并使用CGContextDrawImage

All help is greatly appreciated, but to reiterate the question : "Is there a way to apply the corner radius to the entire CALayer without taking a big performance hit?" 非常感谢所有的帮助,但重申一个问题 :“有没有办法将角落半径应用于整个CALayer而不会造成很大的性能损失?”

cornerRadius does apply to the entire CALayer and it does not cause a big performance hit. cornerRadius确实适用于整个CALayer,它不会造成很大的性能损失。 If you are not seeing the contents with rounded corners, it is because you have forgotten to set masksToBounds to YES. 如果您没有看到带圆角的内容,那是因为您忘记将masksToBounds设置为YES。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM