UICollectionView - 为什么框架标签在第一个和第二个单元格中不起作用 - swift

UICollectionView - why frame label not work In the first and second cell - swift

我的代码:

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 的框架在第一个和第二个单元格中不起作用,只有在后面的单元格中才起作用,为什么? 会是什么呢? 当我回到第二个和第一个单元格时,它一直运行良好,

很奇怪,不是吗? 感谢手表!

现在可以了! 我补充说:

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
}

现在效果很好!!! :)