【发布时间】:2016-05-17 11:49:15
【问题描述】:
我的项目中正在运行一个 collectionView,它通过使用 Photos 框架成功获取 iPhone 照片库。我正在尝试从上一张照片中提升照片 collectionView。我正在使用以下代码....
func getAllPhotosInfo() {
photoAssets = []
let options = PHFetchOptions()
options.sortDescriptors = [
NSSortDescriptor(key: "creationDate", ascending: false)
]
let assets: PHFetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: options)
assets.enumerateObjectsUsingBlock { (asset, index, stop) -> Void in
self.photoAssets.append(asset as! PHAsset)
}
print(photoAssets)
}
//PHAsset到图片的转换
import UIKit
import Photos
class CollectionViewCell: UICollectionViewCell {
var imageManager: PHImageManager?
@IBOutlet weak var photoImageView: UIImageView!
var imageAsset: PHAsset? {
didSet {
self.imageManager?.requestImageForAsset(self.imageAsset!, targetSize: CGSize(width: 320, height: 320), contentMode: .AspectFill, options: nil) { image, info in
self.photoImageView.image = image
}
}
}
}
【问题讨论】:
-
到目前为止一切顺利......似乎有什么问题?
-
@luk2302 我正在 ViewDidLoad 中运行 getAllPhotosInfo() 函数,但它没有提升集合视图...
标签: ios swift photosframework