UIImagePickerController

//从相册里面选择照片

-(void)selectPhoto

{

//    1.创建UIImagePickerController

    UIImagePickerController *pickerVc = [[UIImagePickerController alloc]init];

//    2.设置从相册选择照片

    pickerVc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

//    3.设置委托

    pickerVc.delegate = self;

    

//    4.是否允许编辑

    pickerVc.allowsEditing = YES;

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

   }

 

//拍照

-(void)takePhoto

{

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

//        支持拍照

        //    1.创建UIImagePickerController

        UIImagePickerController *pickerVc = [[UIImagePickerController alloc]init];

        //    2.设置从相机选择照片

        pickerVc.sourceType = UIImagePickerControllerSourceTypeCamera;

        //    3.设置委托

        pickerVc.delegate = self;

    //    4.是否允许编辑

        pickerVc.allowsEditing = YES;

        

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

        }else{

        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"本机不支持拍照" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];

        [alertView show];

    }

}

 

//从相册里面选择照片

-(void)selectPhoto

{

   

//    1.创建UIImagePickerController

    UIImagePickerController *pickerVc = [[UIImagePickerController alloc]init];

//    2.设置从相册选择照片

    pickerVc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

//    3.设置委托

    pickerVc.delegate = self;

    

//    4.是否允许编辑

    pickerVc.allowsEditing = YES;

    

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

    

}

 

 

//照片选择回到方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

{

    _imageView.image = image;

    [picker dismissViewControllerAnimated:YES completion:nil];

}

 

posted @ 2015-09-09 19:33  BN笨的很想飞  阅读(141)  评论(0编辑  收藏  举报