Blame view
App/camera/ALCameraLib/Views/ImageCell.swift
1.56 KB
|
1341bf603
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
//
// ImageCell.swift
// ALImagePickerViewController
//
// Created by Alex Littlejohn on 2015/06/09.
// Copyright (c) 2015 zero. All rights reserved.
//
import UIKit
import Photos
class ImageCell: UICollectionViewCell {
let imageView : UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.layer.masksToBounds = true
imageView.image = UIImage(named: "placeholder",
in: CameraGlobals.shared.bundle,
compatibleWith: nil)
return imageView
}()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(imageView)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func layoutSubviews() {
super.layoutSubviews()
imageView.frame = bounds
}
override func prepareForReuse() {
super.prepareForReuse()
imageView.image = UIImage(named: "placeholder",
in: CameraGlobals.shared.bundle,
compatibleWith: nil)
}
func configureWithModel(_ model: PHAsset) {
if tag != 0 {
PHImageManager.default().cancelImageRequest(PHImageRequestID(tag))
}
tag = Int(PHImageManager.default().requestImage(for: model, targetSize: contentView.bounds.size, contentMode: .aspectFill, options: nil) { image, info in
self.imageView.image = image
})
}
}
|