2017-01-12 1 views
0
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 
    } 
} 

мне нужно объявить изображение, чтобы использовать его в следующем коде, чтобы установить его в качестве фона раздела, но его дает мне ошибку.ошибка: Статический copyWithZone член не может быть использован, например типа UIImageView

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) 

Любая помощь?

ответ

0

UIImageView не соответствует протоколу NSCopying, поэтому copyWithZone не работает. Вы можете создать расширение для UIImageView или его подкласса, где вы реализуете соответствие NSCopying.

+0

Есть ли какой-нибудь пример? или любую ссылку для примера? –

Смежные вопросы