photo

#import "ViewController.h"
#import <CTAssetsPickerController.h>

@interface ViewController () <CTAssetsPickerControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    label.text =  NSLocalizedStringFromTable(@"Name", @"Test", nil);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
        dispatch_async(dispatch_get_main_queue(), ^{
            
            CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
            
            picker.delegate = self;
            
            picker.assetCollectionSubtypes =
            @[@(PHAssetCollectionSubtypeSmartAlbumUserLibrary),
              @(PHAssetCollectionSubtypeAlbumRegular)];
            
            [self presentViewController:picker animated:YES completion:nil];
            
        });
    }];
}

#pragma mark - <CTAssetsPickerControllerDelegate>
- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
    // 關(guān)閉圖片選擇界面
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    // 取出所有選擇的圖片
    PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
    requestOptions.resizeMode   = PHImageRequestOptionsResizeModeExact;
    requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
    PHImageManager *manager = [PHImageManager defaultManager];
    NSInteger index = 0;
    for (PHAsset *asset in assets) {
        [manager requestImageForAsset:asset
                           targetSize:CGSizeMake(100, 100)
                          contentMode:PHImageContentModeAspectFill
                              options:requestOptions
                        resultHandler:^(UIImage *image, NSDictionary *info){
                            UIImageView *imageView = [[UIImageView alloc] init];
                            imageView.image = image;
                            imageView.frame = CGRectMake(110 * (index % 3), 110 * (index / 3), 100, 100);
                            [self.view addSubview:imageView];
                        }];
        
        index++;
    }
}

@end



最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容