首页 > 其他 > 详细

UIImagePickerController

时间:2015-09-09 21:13:40      阅读:169      评论:0      收藏:0      [点我收藏+]

//从相册里面选择照片

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

}

 

UIImagePickerController

原文:http://www.cnblogs.com/xzguo/p/4795740.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!