繁体   English   中英

CollectionView 内容视图在 viewdidload 时不更新/刷新

[英]CollectionView Content View does not update/ refresh when viewdidload

我想在每个 collectionviewcell 中都有这个进度视图(pod) 当我运行应用程序时,进度为 0%,它应该以 100% 的动画进行测试,但它保持在 0%。 只有当我上下滑动(刷新单元格???)它开始动画到 100%。 这是我的代码:

    import UIKit
import MKRingProgressView

class myCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var ringView: UIView!
    let ringsize = 150
    var ringProgressView = RingProgressView()
    override func layoutSubviews() {
         ringProgressView = RingProgressView(frame: CGRect(x: 0, y: 0, width: ringsize, height: ringsize))
        ringProgressView.startColor = .red
        ringProgressView.endColor = .magenta
        ringProgressView.ringWidth = CGFloat(ringsize) * 0.15
        ringProgressView.progress = 0.0
        ringProgressView.shadowOpacity = 0.5
        ringView.addSubview(ringProgressView)
    }
}

extension myCollectionViewCell{
    func setProgress(progress: Double){
        UIView.animate(withDuration: 0.5){
            self.ringProgressView.progress = progress
        }
    }
}


    import UIKit

private let reuseIdentifier = "Cell"

class myCollectionViewController: UICollectionViewController {

    @IBOutlet var myCollectionView: UICollectionView!
    var cellColor = true
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }


    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }


    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of items
        return 7
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! myCollectionViewCell
    
        cell.setProgress(progress: 1.0)
        return cell
    }
}

截屏 有人能帮我吗? 谢谢!!

viewDidAppear方法中调用myCollectionView.reloadData()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM