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
@是的,我更新了我的问题。 –
你有没有对'imageView'应用任何约束? – Wes