简体   繁体   中英

swift: How to load photos from photo library without using 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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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