我的类包含一个UIImage属性,我希望访问它的任何外部客户端都能强制执行该属性作为“复制”属性。但是,当我尝试在我的自定义setter中执行复制时,我得到关于UIImage不支持copyWithZone的运行时错误。那么,什么是确保遵循正确的所有权策略的好方法呢?
// declared in the interface as:
@property (nonatomic, readonly, copy) UIImage *personImage;
// class implementation
- (void)setPersonImage:(UIImage *)newImage
{
if (newImage != personImage)
{
[personImage release];
// UIImage doesn't support copyWithZone
personImage = [newImage copy];
}
}发布于 2014-08-13 09:09:49
因为图像本身是一个指针,所以您需要创建一个图像上下文,将图像绘制到上下文中,然后从上下文中获取原始图像。也许你需要使用UIImage.CGImage。
https://stackoverflow.com/questions/4002040
复制相似问题