zoukankan      html  css  js  c++  java
  • 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];
        }
    }];
  • 相关阅读:
    Springboot中使用ibatis输出日志
    openssl生成iis需要的pfx格式的证书
    SpringBoot 默认日志
    Spring @Value 默认值
    SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成增删改查逻辑
    geomesa hbase geoserver
    在hyper-v中安装centos后配置网络
    linux命令
    SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成ResultMap
    Java 获取指定包下的所有类
  • 原文地址:https://www.cnblogs.com/Apologize/p/6097001.html
Copyright © 2011-2022 走看看