本文介绍了你如何复制CALayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让NSArray充满CALayer的多个实例(所有具有相同的框架,内容等)?

How to you make an NSArray full of multiple instances of a CALayer (all with the same frame, contents etc)?

背景:CALayer需要一些开销要创建,所以我想在类的init方法中创建一些CALayers(都共享相同的属性)(稍后将在该类中使用。)

Background: CALayer takes a bit of overhead to create, so I would like to create a number of CALayers (all sharing the same properties) in the init method of a class (to be used later on in that class.)

推荐答案

CALayer没有内置的 - (id)复制方法。我不知道为什么。然而,给自己打气并不困难。创建CALayer类别并编写自己的复制方法。您所要做的就是实例化并从原始设备手动获取公共ivars / properties并设置为新副本。别忘了打电话 [超级副本]

CALayer doesn't have a built in -(id)copy method. I'm not sure why. It's not difficult to gin up your own however. Create a CALayer category and write your own copy method. All you have to do is instantiate and manually get the public ivars/properties from the original and set to the new copy. Don't forget to call [super copy]

BTW,CALayer是一个对象。您可以将其添加到NSArray。

BTW, CALayer is an object. You can add it to an NSArray.

这篇关于你如何复制CALayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:16
查看更多