当我向后滑动时为什么UIImageView会变空?

时间:2016-11-16 14:06:11

标签: ios swift uiimageview

我的UICollectionView中有一个UIViewController(包含在UINavigationContoller中)。在UICollectionViewCell中,我创建了一个带有gif网址的UIImageView。(使用Kingfisher

imageView按预期工作,但只要我"尝试"它就会变得空白。滑回上一个UIViewController。当我取消"向后滑动手势"时,imageView再次显示gif。

奇怪的是,单击后退指示器时,imageView没有变空。

另外,如果我将静态图像设置为imageView,则imageView不会变空。

有谁知道如何解决这个问题?

这是一个演示:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationController?.pushViewController(ViewController2(), animated: true)
    }
}

class ViewController2: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.whiteColor()

        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSize(width: 100, height: 100)
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.dataSource = self
        collectionView.backgroundColor = UIColor.clearColor()
        collectionView.registerClass(CollectionViewCell.self, forCellWithReuseIdentifier: "cell")
        view.addSubview(collectionView)

        collectionView.snp_makeConstraints { (make) in
            make.top.equalTo(snp_topLayoutGuideBottom)
            make.left.right.bottom.equalTo(view)
        }
    }

}

extension ViewController2: UICollectionViewDataSource {
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 20
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
        cell.imageView.animationImages = [UIImage(named: "1")!, UIImage(named: "2")!]
        cell.imageView.startAnimating()
        return cell
    }
}

class CollectionViewCell: UICollectionViewCell {
    lazy var imageView: UIImageView = {
        let view = UIImageView()
        view.clipsToBounds = true
        view.contentMode = .ScaleAspectFill
        return view
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)

        contentView.addSubview(imageView)
        imageView.snp_makeConstraints { (make) in
            make.edges.equalTo(contentView)
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

我认为这是一个UIImageView问题。

0 个答案:

没有答案