UIImagePickerController 用法

来源:互联网 发布:锐捷网络2016年销售额 编辑:程序博客网 时间:2024/06/06 15:45
//首选需要遵循协议 <UIImagePickerControllerDelegate,UINavigationControllerDelegate>//如果是imageView的话, interactionEnabled必须设置为YES    self.headImageView.userInteractionEnabled = YES;    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondToTapGesture:)];    [self.headImageView addGestureRecognizer:tapGesture];//手势方法-(void)respondToTapGesture:(UITapGestureRecognizer *)gestrue{        UIImagePickerController * imageController = [[UIImagePickerController alloc]init];        imageController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//数据源类型有三种 ![UIImagePickerControllerSourceTypePhotoLibrary](http://img.blog.csdn.net/20160502162802766)UIImagePickerControllerSourceTypeCamera这种方式直接打开设备相机取图![UIImagePickerControllerSourceTypeSavedPhotosAlbum](http://img.blog.csdn.net/20160502163631270)        imageController.allowsEditing = YES; //设置可以编辑        imageController.delegate = self;//设定委托        [self presentViewController:imageController animated:YES completion:nil];}//UIImagePickerControllerDelegate 协议方法- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{    UIImage *image = info[@"UIImagePickerControllerEditedImage"];    self.headImageView.image = image;    [self dismissViewControllerAnimated:YES completion:nil];}
0 0
原创粉丝点击