Now 第三方库 GitHub 地址飞机票: GitHub-JKImagePicker
首先包含所需的头文件,并添加代理.
Code 如下:
#pragma mark -更换头像相关
- (void)changeHeadImg {
alertConImg= [UIAlertController alertControllerWithTitle:nilmessage:nilpreferredStyle:UIAlertControllerStyleActionSheet];
[alertConImg addAction:[UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction*_Nonnullaction) {
/**取消*/
}]];
[alertConImg addAction:[UIAlertAction actionWithTitle:@"拍照"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {
/**拍照*/
}]];
[alertConImg addAction:[UIAlertAction actionWithTitle:@"从手机相册选取"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {
/**从手机相册选取*/
JKImagePickerController*imgPickerCon = [[JKImagePickerController alloc] init];
imgPickerCon.delegate=self;
imgPickerCon.showsCancelButton=YES;//显示取消按钮
imgPickerCon.allowsMultipleSelection=YES;//允许多个选择
imgPickerCon.minimumNumberOfSelection= 1;//最小选择的数量
imgPickerCon.maximumNumberOfSelection= 9;//最大选择的数量
imgPickerCon.selectedAssetArray=self.arrSletedHeadImg;//装载选择的照片
YQBaseNavigationController*navCon = [[YQBaseNavigationController alloc] initWithRootViewController:imgPickerCon];
[self presentViewController:navCon animated:YES completion:^{
//
}];
}]];
[self presentViewController:alertConImg animated:YES completion:^{
/**调相机功能PickerCon*/
}];
}
#pragma mark -相机或相册获取图片回调相关代理方法
- (void)imagePickerController:(JKImagePickerController*)imagePicker didSelectAsset:(JKAssets*)asset isSource:(BOOL)source {
[imagePicker dismissViewControllerAnimated:YES completion:^{
//
}];
}
- (void)imagePickerController:(JKImagePickerController*)imagePicker didSelectAssets:(NSArray*)assets isSource:(BOOL)source {
self.arrSletedHeadImg= [NSMutableArray arrayWithArray:assets];
for(int i = 0; i
JKAssets*asset = [self.arrSletedHeadImg objectAtIndex:i];
ALAssetsLibrary*lib = [[ALAssetsLibrary alloc] init];
[lib assetForURL:asset.assetPropertyURLresultBlock:^(ALAsset*asset) {
//
}failureBlock:^(NSError*error) {
NSLog(@"YQMyInfoViewController.h --- imgPickerCon --- error --- %@", error);
}];
}
[imagePicker dismissViewControllerAnimated:YES completion:^{
/**点击完成回调*/
}];
}
- (void)imagePickerControllerDidCancel:(JKImagePickerController*)imagePicker {
[imagePicker dismissViewControllerAnimated:YES completion:^{
//
}];
}