// 调用图片选择器
- (void)callImagePicker{
[self.view endEditing:YES];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择图片来源" delegate:selfcancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从手机相册选择", nil];
[sheet showInView:self.view];
}
#pragma mark - actionSheet的协议方法 ----- 继续上传图片
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
UIImagePickerController *ipVC = [[UIImagePickerController alloc] init];
ipVC.delegate = self;
ipVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
if (buttonIndex == 0) {
BOOL isCamera = [UIImagePickerControllerisCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
if (isCamera) {
ipVC.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:ipVC animated:YES completion:nil];
}
}else if(buttonIndex==1){
// ipVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsMultipleSelection =YES;
imagePickerController.minimumNumberOfSelection = 1;
imagePickerController.maximumNumberOfSelection = 9;
imagePickerController.hidesBottomBarWhenPushed=YES;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController];
[self presentViewController:navigationController animated:YES completion:NULL];
}else{
}
}
- (void)dismissImagePickerController
{
if (self.presentedViewController) {
[self dismissViewControllerAnimated:YES completion:NULL];
} else {
[self.navigationController popToViewController:self animated:YES];
}
}
#pragma mark - QBImagePickerControllerDelegate
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(ALAsset *)asset
{
NSLog(@"*** imagePickerController:didSelectAsset:");
NSLog(@"%@", asset);
[self dismissImagePickerController];
}
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray*)assetss
{
NSLog(@"assetss:%@",assetss);
NSMutableArray *imagesArr = [[NSMutableArray alloc]init];
UIImage *originImage ;
for (int i=0; i<assetss.count; i++) {
originImage = [UIImage imageWithCGImage:[[assetss objectAtIndex:i] aspectRatioThumbnail]];
[imagesArr addObject:originImage];
}
//
[UploadImageTool uploadImages:imagesArr progress:^(CGFloat progress) {
NSLog(@"qin niu --%f",progress);
} success:^(NSArray *urlArr) {
NSLog(@"qin niu --%@",urlArr);
for (int i=0; i<urlArr.count; i++) {
if (imageData.count<10) {
[imageData insertObject:urlArr[i] atIndex:imageData.count-1];
}
}
if (imageData.count==0) {
_collectionView.height = 120;
}else if (imageData.count<=3) {
_collectionView.height = 120;
}else if (imageData.count>3&&imageData.count<=6){
_collectionView.height = 240;
}else if (imageData.count>6&&imageData.count<=10){
_collectionView.height = 350;
}
thirdView.height = _collectionView.bottom;
fistView.top = thirdView.bottom+10;
fourView.top = fistView.bottom+10;
commitBtn.top = fourView.bottom+50;
_scrollView.contentSize = CGSizeMake(0, commitBtn.bottom+20);
[_collectionView reloadData];
} failure:^{
NSLog(@" --->> error: ");
}];
[self dismissImagePickerController];
}
#pragma mark - UIImagePickerController 代理方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
//对获取的图片进行一些处理
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
//
[UploadImageTool uploadImages:@[image] progress:^(CGFloat progress) {
NSLog(@"qin niu --%f",progress);
} success:^(NSArray *urlArr) {
NSLog(@"qin niu --%@",urlArr);
if (imageData.count<10) {
[imageData insertObject:urlArr[0] atIndex:imageData.count-1];
}
if (imageData.count==0) {
_collectionView.height = 120;
}else if (imageData.count<=3) {
_collectionView.height = 120;
}else if (imageData.count>3&&imageData.count<=6){
_collectionView.height = 240;
}else if (imageData.count>6&&imageData.count<=10){
_collectionView.height = 350;
}
thirdView.height = _collectionView.bottom;
fistView.top = thirdView.bottom+10;
fourView.top = fistView.bottom+10;
commitBtn.top = fourView.bottom+50;
_scrollView.contentSize = CGSizeMake(0, commitBtn.bottom+20);
[_collectionView reloadData];
} failure:^{
NSLog(@" --->> error: ");
}];
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
{
NSLog(@"*** imagePickerControllerDidCancel:");
[self dismissImagePickerController];
}