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)
}
}
私はちょうど細胞が表示されたときに任意のオフセットを見ることができません。私は間違っているのですか?
サブクラス固有のものでない限り、 'UICollectionViewCell'には' offset'というプロパティはありません。 – Wes
@Wesはい質問を更新しました。 –
'imageView'に適用される制約はありますか? – Wes