2016-11-22 4 views
0

コレクションビューセルのコンテンツオフセットを作成する方法。私が持っているが、それが何らかの理由で動作しません。何をすべきか、以下のコード:コレクションビューセルのコンテンツのオフセット。

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "pCell", for: indexPath) as! CollectionViewCell 
    cell.imageView.image = UIImage(named: "1")! 

    cell.offset(offset: CGPoint(x: 0.0, y: -30.0)) 

    return cell 
    } 

マイセルクラスのコードは:

class CollectionViewCell: UICollectionViewCell { 

    @IBOutlet weak var imageView: UIImageView! 
    var image: UIImage = UIImage() { 
    didSet{ 
     self.imageView.image = image 
    } 
    } 

    func offset(offset: CGPoint) { 
    self.imageView.frame = self.imageView.bounds.offsetBy(dx: offset.x, dy: offset.y) 
    } 
} 

私はちょうど細胞が表示されたときに任意のオフセットを見ることができません。私は間違っているのですか?

+0

サブクラス固有のものでない限り、 'UICollectionViewCell'には' offset'というプロパティはありません。 – Wes

+0

@Wesはい質問を更新しました。 –

+0

'imageView'に適用される制約はありますか? – Wes

答えて

1

imageViewにIB制約が有効になっていないことを確認してください。そうしないと、フレームが更新されなくなります。

関連する問題