我的代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as? GuideGalleryCell
cell!.configureCell(listImages[indexPath.row])
return cell!
}
代码 - func configureCell:
func configureCell(_imageText:ImageText){
imageText = _imageText
image = System.retrieveImage(imageText.nvImage, fromCity: System.instance().currentOrder.packageName)
imageView.image = image
// if let text = imageText.nvText{
lblTitle.text = imageText.nvText
var s:NSString=imageText.nvText
var frame = self.viewLblTitle.frame
frame.origin.y = self.bounds.size.height
self.viewLblTitle.frame = frame
var frmageImage = image.size
if(!(s.isEqualToString("")))
{
UIView.animateWithDuration(0.7, animations: { () -> Void in
if self.image.size.height > self.image.size.width{
var newY = (self.image.size.height - self.viewLblTitle.frame.size.height)
var frame = self.viewLblTitle.frame
frame.origin.y = newY
self.viewLblTitle.frame = frame
}else{
var t = (self.bounds.size.height - 64 - self.image.size.height)/2
var newY = self.image.size.height - self.viewLblTitle.frame.size.height + t
println(newY)
var frame = self.viewLblTitle.frame
frame.origin.y = newY
self.viewLblTitle.frame = frame
}
})
}
}
viewLblTitle 的框架不起作用,第一个和第二个单元格仅在以下单元格中起作用,为什么? 会是什么呢? 当我回到第二个和第一个牢房时,它运行良好,
很奇怪,不是吗? 感谢 watch !
最佳答案
现在可以了! 我补充道:
dispatch_async(dispatch_get_main_queue())
调用函数configureCell之前
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell:GuideGalleryCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! GuideGalleryCell
dispatch_async(dispatch_get_main_queue()) {
cell.configureCell(self.listImages[indexPath.row])
}
return cell
}
现在效果很好!!! :)
关于swift - UICollectionView - 为什么框架标签在第一个和第二个单元格中不起作用 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32176190/