// 调用图片选择器
- (void)callImagePicker{
[self.viewendEditing:YES];
UIActionSheet *sheet = [[UIActionSheetalloc]initWithTitle:@"选择图片来源"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"拍照",@"从手机相册选择",nil];
[sheet showInView:self.view];
}
#pragma mark - actionSheet的协议方法 -----继续上传图片
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
UIImagePickerController *ipVC = [[UIImagePickerControlleralloc]init];
ipVC.delegate =self;
ipVC.modalTransitionStyle =UIModalTransitionStyleCoverVertical;
if (buttonIndex ==0) {
BOOL isCamera = [UIImagePickerControllerisCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
if (isCamera) {
ipVC.sourceType =UIImagePickerControllerSourceTypeCamera;
[selfpresentViewController:ipVCanimated:YEScompletion:nil];
}
}elseif(buttonIndex==1){
// ipVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
QBImagePickerController *imagePickerController = [[QBImagePickerControlleralloc]init];
imagePickerController.delegate =self;
imagePickerController.allowsMultipleSelection =YES;
imagePickerController.minimumNumberOfSelection =1;
imagePickerController.maximumNumberOfSelection =9;
imagePickerController.hidesBottomBarWhenPushed=YES;
UINavigationController *navigationController = [[UINavigationControlleralloc]initWithRootViewController:imagePickerController];
[selfpresentViewController:navigationControlleranimated:YEScompletion:NULL];
}else{
}
}
- (void)dismissImagePickerController
{
if (self.presentedViewController) {
[selfdismissViewControllerAnimated:YEScompletion:NULL];
} else {
[self.navigationControllerpopToViewController:selfanimated:YES];
}
}
#pragma mark - QBImagePickerControllerDelegate
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(ALAsset *)asset
{
NSLog(@"*** imagePickerController:didSelectAsset:");
NSLog(@"%@", asset);
[selfdismissImagePickerController];
}
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assetss
{
NSLog(@"assetss:%@",assetss);
NSMutableArray *imagesArr = [[NSMutableArrayalloc]init];
UIImage *originImage ;
for (int i=0; i<assetss.count; i++) {
originImage = [UIImageimageWithCGImage:[[assetssobjectAtIndex:i]aspectRatioThumbnail]];
[imagesArr addObject:originImage];
}
//
[UploadImageTooluploadImages:imagesArrprogress:^(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) {
[imageDatainsertObject:urlArr[i]atIndex:imageData.count-1];
}
}
if (imageData.count==0) {
_collectionView.height =120;
}elseif (imageData.count<=3) {
_collectionView.height =120;
}elseif (imageData.count>3&&imageData.count<=6){
_collectionView.height =240;
}elseif (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);
[_collectionViewreloadData];
} failure:^{
NSLog(@" --->> error: ");
}];
[selfdismissImagePickerController];
}
#pragma mark - UIImagePickerController 代理方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//对获取的图片进行一些处理
UIImage *image = [infoobjectForKey:@"UIImagePickerControllerOriginalImage"];
//
[UploadImageTooluploadImages:@[image]progress:^(CGFloat progress) {
NSLog(@"qin niu --%f",progress);
} success:^(NSArray *urlArr) {
NSLog(@"qin niu --%@",urlArr);
if (imageData.count<10) {
[imageDatainsertObject:urlArr[0]atIndex:imageData.count-1];
}
if (imageData.count==0) {
_collectionView.height =120;
}elseif (imageData.count<=3) {
_collectionView.height =120;
}elseif (imageData.count>3&&imageData.count<=6){
_collectionView.height =240;
}elseif (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);
[_collectionViewreloadData];
} failure:^{
NSLog(@" --->> error: ");
}];
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
- (void)imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
{
NSLog(@"*** imagePickerControllerDidCancel:");
[selfdismissImagePickerController];
}