swift:如何在不使用UIImagePickerController的情况下从照片库加载照片? [英] swift: How to load photos from photo library without using UIImagePickerController?

查看:93
本文介绍了swift:如何在不使用UIImagePickerController的情况下从照片库加载照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用swift从照片库加载图片。我知道我可以使用UIImagePickerController让用户从相机胶卷中选择图像,但我想在没有用户操作的情况下访问照片。例如,我想阅读一系列来自相机胶卷的照片,并将它们放在照片幻灯片中,逐一显示。如何在没有UIImagePickerController的情况下访问这些照片?

I am using swift to load images from photo library. I know that I can use UIImagePickerController to let user to choose the images from camera roll but I want to access photos without user actions. For example, I want to read a series of photos which are from camera roll and put them in a photo slide to show them one by one. How can I access these photos without UIImagePickerController?

推荐答案

您可以使用照片框架(适用于iOS 8+)。请查看示例。在AAPLRootListViewController的代码中,如果使用awakeFromNib方法,您可以看到如何创建PHFetchResult对象以检索特定的照片数据。然后,在AAPLAssetGridViewController中,PHAsset对象(来自PHFetchResult)用于检索实际图像数据。看一下方法

You can access photo library using Photos framework(for iOS 8+). Take a look at this example. In AAPLRootListViewController's code if awakeFromNib method you can see how to create PHFetchResult object to retrieve specific photos data. Then, in AAPLAssetGridViewController, PHAsset objects(from PHFetchResult) are used for retrieving actual image data. Take a look at method

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

代码是用Objective-C而不是Swift编写的,但你可以使用Swift做同样的事情。提出问题,如果有的话。

The code is written in Objective-C rather than Swift, but you could do the same using Swift. Ask questions if any.

这篇关于swift:如何在不使用UIImagePickerController的情况下从照片库加载照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆