调用相机主要用到的类 UIImagePickerController UIImagePickerControllerDelegate

UIImagePickerController

打开相册或者相机可以在vc中 present 该类实例对象,IOS8有个bug,可以通过如下方法解决:

UIImagePickerController *pvc=[UIImagePickerController new];
    pvc.delegate=self;


    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){

        pvc.sourceType=UIImagePickerControllerSourceTypeCamera;
    }else{
        pvc.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

    }

    if([[[UIDevice
          currentDevice] systemVersion] floatValue]>=8.0) {
//bug:Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates. 解决     
        pvc .modalPresentationStyle=UIModalPresentationOverCurrentContext;

    }

  [self presentViewController:pvc animated:YES completion:nil];

UIImagePickerControllerDelegate 选定照片结束回调方法

//选择图片渲染 view
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    UIImage *image=info[UIImagePickerControllerOriginalImage];

    _myImageView.image=image;
    [self dismissViewControllerAnimated:YES completion:nil];
}

//取消选择 返回
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    NSLog(@" %@ ",@"cancel pick");
    [self dismissViewControllerAnimated:YES completion:nil];
}

相册照片多选

照片多选引入这个库 :https://github.com/questbeat/QBImagePicker

照片多选


hqman
198 声望8 粉丝