IOS七牛上传图片

// 调用图片选择器

- (void)callImagePicker{  

    [self.view endEditing:YES];

    UIActionSheet *sheet = [[UIActionSheet allocinitWithTitle:@"选择图片来源" delegate:selfcancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从手机相册选择"nil];

    [sheet showInView:self.view];

}



#pragma mark - actionSheet的协议方法 ----- 继续上传图片

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    UIImagePickerController *ipVC = [[UIImagePickerController allocinit];

    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 allocinit];

        imagePickerController.delegate = self;

        imagePickerController.allowsMultipleSelection =YES;

        imagePickerController.minimumNumberOfSelection = 1;

        imagePickerController.maximumNumberOfSelection = 9;

        imagePickerController.hidesBottomBarWhenPushed=YES;

        UINavigationController *navigationController = [[UINavigationController allocinitWithRootViewController: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(0commitBtn.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[0atIndex: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(0commitBtn.bottom+20);

        [_collectionView reloadData];

        

    } failure:^{

        

        NSLog(@" --->> error:   ");

        

    }];

    

    [picker dismissViewControllerAnimated:YES completion:nil];

    

}

- (void)imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController

{

    NSLog(@"*** imagePickerControllerDidCancel:");

    [self dismissImagePickerController];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值