第三方庫 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:^{
//
}];
}