第三方库 GitHub 地址:
https://github.com/pjk1129/JKImagePicker/tree/master/JKImagePicker/ImagePicker/Assets
首先包含所需的头文件,并添加代理.
Code 如下:
#pragma mark -更换头像相关
- (void)changeHeadImg {
alertConImg= [UIAlertControlleralertControllerWithTitle:nilmessage:nilpreferredStyle:UIAlertControllerStyleActionSheet];
[alertConImgaddAction:[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction*_Nonnullaction) {
/**取消*/
}]];
[alertConImgaddAction:[UIAlertActionactionWithTitle:@"拍照"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {
/**拍照*/
}]];
[alertConImgaddAction:[UIAlertActionactionWithTitle:@"从手机相册选取"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {
/**从手机相册选取*/
JKImagePickerController*imgPickerCon = [[JKImagePickerControlleralloc]init];
imgPickerCon.delegate=self;
imgPickerCon.showsCancelButton=YES;//显示取消按钮
imgPickerCon.allowsMultipleSelection=YES;//允许多个选择
imgPickerCon.minimumNumberOfSelection= 1;//最小选择的数量
imgPickerCon.maximumNumberOfSelection= 9;//最大选择的数量
imgPickerCon.selectedAssetArray=self.arrSletedHeadImg;//装载选择的照片
YQBaseNavigationController*navCon = [[YQBaseNavigationControlleralloc]initWithRootViewController:imgPickerCon];
[selfpresentViewController:navConanimated:YEScompletion:^{
//
}];
}]];
[selfpresentViewController:alertConImganimated:YEScompletion:^{
/**调相机功能PickerCon*/
}];
}
#pragma mark -相机或相册获取图片回调相关代理方法
- (void)imagePickerController:(JKImagePickerController*)imagePicker didSelectAsset:(JKAssets*)asset isSource:(BOOL)source {
[imagePickerdismissViewControllerAnimated:YEScompletion:^{
//
}];
}
- (void)imagePickerController:(JKImagePickerController*)imagePicker didSelectAssets:(NSArray*)assets isSource:(BOOL)source {
self.arrSletedHeadImg= [NSMutableArrayarrayWithArray:assets];
for(inti = 0; i
JKAssets*asset = [self.arrSletedHeadImgobjectAtIndex:i];
ALAssetsLibrary*lib = [[ALAssetsLibraryalloc]init];
[libassetForURL:asset.assetPropertyURLresultBlock:^(ALAsset*asset) {
//
}failureBlock:^(NSError*error) {
NSLog(@"YQMyInfoViewController.h --- imgPickerCon --- error --- %@", error);
}];
}
[imagePickerdismissViewControllerAnimated:YEScompletion:^{
/**点击完成回调*/
}];
}
- (void)imagePickerControllerDidCancel:(JKImagePickerController*)imagePicker {
[imagePickerdismissViewControllerAnimated:YEScompletion:^{
//
}];
}