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

标签 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 的框架不起作用,第一个和第二个单元格仅在以下单元格中起作用,为什么? 会是什么呢? 当我回到第二个和第一个牢房时,它运行良好,

很奇怪,不是吗? 感谢 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/

相关文章:

ios - 改变不同变量的动画回调

ios - 在出现之前重新加载 UICollectionView,而用户不会看到更改

ios - 我可以使用 swift 在 iOS 中围绕 y 轴旋转一个对象,但是如何围绕一个轴旋转多个对象?

ios - 在远程推送通知重定向到正确的 ViewController

swift - 如果按钮宽度大于按钮图像的宽度(xcode),则将按钮图像保持在左侧位置

swift - 创建一个 slider ,如果释放到最大值,该 slider 会更改最大值

Swift:选择 UICollectionViewCell(在 UITableViewCell 内)时如何使用 Segue

ios - 在 UICollectionView 和 UITableView 中优化预加载/预取图像

像 iOS collectionView 一样具有多列的 android 表

ios - CollectionView 未显示任何项目