复制 UIImageView 子类

发布于 2024-11-08 02:37:00 字数 799 浏览 4 评论 0原文

我的数组中有几个对象。这些对象来自 UIImageView 子类。

这些对象的类有几个@synthesized 属性。

在某些时候,我必须在数组上给定位置的不同坐标处创建对象的副本。然后我这样做:

id objectToDuplicate = [myArray objectAtIndex:x];
id newObject = [objectToDuplicate copy];
CGPoint newCenter = [objectToDuplicate center];
newCenter.x = newCenter.x + 10;
newCenter.y = newCenter.y + 10;
[newObject setCenter:newCenter];
[self.view addSubview:newObject];
[newObject release];

当这段代码运行时,什么也没有发生。我的意思是,没有创建具有 10 像素偏移的对象,并且我在控制台中看到以下消息:

** ... copyWithZone:]:无法识别的选择器发送到实例... **

对象具有多个元素,例如文本框、标签和具有阴影、发光等的图像,并且新对象必须具有文本颜色、阴影、发光、大小、图像等的值与原始值相同。

我认为 UIImageView 具有 NSCopying 协议。如果这是问题,我该如何实施?

请不要向我发送文档,我已阅读它们,这就是我在这里询问的原因。请给我一些实际的例子。

谢谢。

I have several objects in an array. These objects are from a UIImageView subclass.

These objects' class has several @synthesized properties.

At some point I have to create a duplicate of an object in a given position on the array at a different coordinate. Then I do:

id objectToDuplicate = [myArray objectAtIndex:x];
id newObject = [objectToDuplicate copy];
CGPoint newCenter = [objectToDuplicate center];
newCenter.x = newCenter.x + 10;
newCenter.y = newCenter.y + 10;
[newObject setCenter:newCenter];
[self.view addSubview:newObject];
[newObject release];

When this code runs, nothing happens. I mean, no object is created with a 10 pixel offset and I see this message in the console:

** ... copyWithZone:]: unrecognized selector sent to instance ... **

The objects have several elements such as text boxes, labels, and images that have shadow, glow, etc., and the new object has to have the same values for text colors, shadows, glows, size, images, etc., as the original.

I thought UIImageView had the NSCopying protocol in place. If this is the problem, how do I implement that?

Please refrain from sending me to the docs, I have read them and this is why I am asking here. Please give me practical examples.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-11-15 02:37:00

您在哪里读到 UIImageView 实现 NSCopying ?事实并非如此,您必须自己为您的子类执行此操作。

Where did you read that UIImageView implements NSCopying? It doesn't, you have to do that yourself for your subclass.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文