2016-05-17 6 views
0

Ich habe eine SammlungView in meinem Projekt ausgeführt, die iPhone-Fotobibliothek mithilfe von Fotos Rahmen erfolgreich abruft.Ich versuche, die FotosammlungView vom letzten Foto.Ich benutze den folgenden Code ....Fotos Rahmen aufsteigend in Swift

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 zur Bildumwandlung

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 
     } 

    } 
} 

}

+0

So weit so gut ... was scheint das Problem zu sein? – luk2302

+0

@ luk2302 Ich führe die Funktion getAllPhotosInfo() innerhalb der ViewDidLoad, aber nicht die Sammlungsansicht aufsteigend ... – Joe

Antwort

0

ich war mit den Fotos Rahmen doc spielen, und ich fand die answer.here ist der worki ng code ....

var photoAssets = [PHAsset]() 

func getAllPhotosInfo() { 
    photoAssets = [] 

    let options = PHFetchOptions() 
    options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: false) ] 
    options.predicate = NSPredicate(format: "mediaType = %i", PHAssetMediaType.Image.rawValue) 
    let assetCollections = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.SmartAlbum, subtype: PHAssetCollectionSubtype.SmartAlbumUserLibrary, options: nil) 

for i in 0 ..< assetCollections.count 
{ 

     if let assetCollection = assetCollections[i] as? PHAssetCollection 
     { 
      images = PHAsset.fetchAssetsInAssetCollection(assetCollection, options: options) 

      print(images.count) 

      return 
     } 
    } 
} 
Verwandte Themen