IOS7-UIImagePickerController使用

来源:互联网 发布:淘宝开店装修店铺 编辑:程序博客网 时间:2024/05/16 14:13
@interface CapturePicViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>@property(nonatomic,retain) UIImagePickerController *imgPickerCtl;@end@implementation CapturePicViewController@synthesize imgPickerCtl;- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.    [self loadImgPicker];    }- (void)loadImgPicker{    imgPickerCtl = [[UIImagePickerController alloc]init];
    //调用摄像头捕捉图片显示出来    //Camera    imgPickerCtl.sourceType = UIImagePickerControllerSourceTypeCamera;
    //读取相册的图片显示出来    //photo library    //imgPickerCtl.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;    imgPickerCtl.delegate = self;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [self presentViewController:imgPickerCtl animated:YES completion:nil];}- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{    [imgPickerCtl dismissViewControllerAnimated:YES completion:^{        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];        imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];        [self.view addSubview:imageView];    }];}

0 0
原创粉丝点击