iOS相冊中圖片按照時間排序


ios相冊默認是按照時間從過去到現在排列,圖片順序有正序和逆序,group可以用以下方法來選擇順序

/** @param NSIndexSet 需要獲取的相冊中圖片范圍 @param NSEnumerationOptions 獲取圖片的順序(順序還是逆序) //ALAssetsGroupEnumerationResultsBlock的參數 @param result 照片ALAsset對象 @param index 當前result在該group相冊中的位置,第index位置上 @param *stop 需要停止的時候 *stop = YES就停止繼續運行當前相冊group */ enumerateAssetsAtIndexes:(NSIndexSet *)indexSet options:(NSEnumerationOptions)options usingBlock:(ALAssetsGroupEnumerationResultsBlock)enumerationBlock

示例如下

@property (nonatomic, strong) ALAssetsGroup *selectAssetsGroup;
-(void)loadAllPhotos{ NSInteger photoNumber = [self.selectAssetsGroup numberOfAssets]; NSIndexSet *IndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, photoNumber)]; //圖片按照逆序排列(由現在到過去)
    [self.selectAssetsGroup enumerateAssetsAtIndexes:IndexSet options:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { if (result) { numberOfAssets++; NSString *type = [result valueForProperty:ALAssetPropertyType]; if ([type isEqualToString:ALAssetTypePhoto]){ numberOfPhotos++; }else if ([type isEqualToString:ALAssetTypeVideo]){ numberOfVideos++; } [assets addObject:result]; } }]; }

若只想按照系統默認的順序(由過去到現在),那么可以用

[self.selectAssetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { if (result) { numberOfAssets++; NSString *type = [result valueForProperty:ALAssetPropertyType]; if ([type isEqualToString:ALAssetTypePhoto]){ numberOfPhotos++; }else if ([type isEqualToString:ALAssetTypeVideo]){ numberOfVideos++; } [assets addObject:result]; } }];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM