UICollectionView
がUIViewController
に追加され、カスタムセルが作成されました。UICollectionViewCellのコンテンツの最初の読み込み時のサイズが正しくない
sizeForItemAtIndexPath
メソッドを使用してセルのサイズを設定し、各セルを高さと幅の両方でUIScreen.mainScreen().bounds.width/2
に設定しました。したがって、本質的に、各セルは画面幅の半分で、同じ長さの高さです。
次に、セル内にUIImageView
があり、各エッジがセルの相対端に固定され、イメージビューがセルを塗りつぶすようになります。私はまた、セル内に垂直方向と水平方向の両方に中心があるUILabel
を持っています。
最初の読み込みでは、セルは正しいサイズですが、内容は左上の小さな正方形ではるかに小さくなります。 (下の画像では、セルのcontentViewの背景色を緑に、imageViewの背景色を赤に設定しています)。
は、その後少し下にスクロールした後の細胞のすべてが細かい(とバックアップにスクロールした後、細かいまま)(と私は、再利用可能なセルがデキューされていると仮定します)。コンテンツが最初のロード時に正しく制約されないように引き起こしている何?
UPDATE
私UIViewController
からのコードの一部:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("PrevDrawCell", forIndexPath: indexPath) as? PrevDrawCell
if cell == nil {
cell = PrevDrawCell()
}
cell!.drawVC = self
cell!.imageShortCode = self.tempImageURLs[indexPath.row]
// Pull image (async) and set after download
cell!.setupImage()
cell!.contentView.backgroundColor = UIColor.greenColor()
cell!.coverView.backgroundColor = UIColor.redColor()
cell!.dateLabel.font = UIFont(name: "HelveticaNeue-Light", size: 26)
cell!.dateLabel.text = "\(self.tempImageURLs.count-indexPath.row)/9"
return cell!
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let size = UIScreen.mainScreen().bounds.width/2
return CGSize(width: size, height: size)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsetsZero
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
Show 'UIViewController' – Arsen
' UIViewController'のコードを表示することを意味していますか? – myles
はい、コードを表示 – Arsen