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

时间:2015-08-24 07:01:53

标签: swift uicollectionview

我的代码:

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的框架只能在它工作的单元格之后才能使用第一个和第二个单元格,为什么? 会是什么呢? 当我回到第二个和第一个细胞时,它一直运作良好,

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

1 个答案:

答案 0 :(得分:0)

现在它有效! 我补充说:

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
}

现在它运作良好!!! :)