Ios 错误:静态成员copyWithZone不能用于UIImageView类型的实例
我需要声明一个图像,以便在下面的代码中使用它来将其设置为节背景,但它给了我一个错误Ios 错误:静态成员copyWithZone不能用于UIImageView类型的实例,ios,swift,uiimageview,uicollectionview,Ios,Swift,Uiimageview,Uicollectionview,我需要声明一个图像,以便在下面的代码中使用它来将其设置为节背景,但它给了我一个错误 class MDCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes { var color: UIColor = UIColor.whiteColor() var image : UIImageView! override func copyWithZone(zone: NSZone) -> AnyOb
class MDCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes
{
var color: UIColor = UIColor.whiteColor()
var image : UIImageView!
override func copyWithZone(zone: NSZone) -> AnyObject
{
let newAttributes: MDCollectionViewLayoutAttributes = super.copyWithZone(zone) as! MDCollectionViewLayoutAttributes
newAttributes.color = self.color.copyWithZone(zone) as! UIColor
newAttributes.image = UIImageView(frame:newAttributes.bounds)
newAttributes.image.image = UIImage(named:"Appetizer.png")
newAttributes.image = self.image.copyWithZone(zone) as! UIImageView// this is giving me an error
return newAttributes
}
}
有什么帮助吗?UIImageView不符合NSCopying协议,这就是copyWithZone无法工作的原因。您可以创建UIImageView或其子类的扩展,在其中实现NSCopying一致性。UIImageView不符合NSCopying协议,这就是copyWithZone不起作用的原因。您可以创建UIImageView或其子类的扩展,在其中实现NSCopying一致性。有没有任何示例?或者任何一个例子的链接?有任何例子吗?或者以任何链接为例?
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]?
{
let attributes = super.layoutAttributesForElementsInRect(rect)
var allAttributes = [UICollectionViewLayoutAttributes]()
if let attributes = attributes
{
for attr in attributes
{
if (attr.representedElementCategory == UICollectionElementCategory.Cell && attr.frame.origin.x == self.sectionInset.left)
{
let decorationAttributes = SBCollectionViewLayoutAttributes(forDecorationViewOfKind: "sectionBackground", withIndexPath: attr.indexPath)
// decorationAttributes.color = UIColor.brownColor().colorWithAlphaComponent(1)