美文网首页
调用本地相册本地相机

调用本地相册本地相机

作者: 花果山上的程序猿 | 来源:发表于2016-04-22 11:16 被阅读0次

    访问本地相册

    1 需要签两个协议                  <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

    2 创建UIImagePickerController来访问相册UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    3 签代理  picker.delegate = self;

    4 picker.allowsEditing = YES;  然后允许进行编辑

    5 进行跳转 [self presentViewController:picker animated:YES completion:^{}];

    6 在- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info方法中获取图片

    7 UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 从字典里提取info里的图片内容

    8 self.imageView.image= image; 把图片赋给UIImageView

    9 用户交互一定要打开 self.imageView.userInteractionEnabled=YES;

    访问本地相机

    1 UIImagePickerControllerSourceTypetype =UIImagePickerControllerSourceTypeCamera; 先把SourceType设置为相机

    2 type =UIImagePickerControllerSourceTypeCamera;  照相机

    3 sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 保存的相片

    4 创建UIImagePickerController                UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    5 签代理 picker.delegate = self;

    6 picker.allowsEditing = YES; 设置可编辑

    7 picker.sourceType = sourceType;

    8 [self presentModalViewController:picker animated:YES]; 进入照相界面

    相关文章

      网友评论

          本文标题:调用本地相册本地相机

          本文链接:https://www.haomeiwen.com/subject/mnqxrttx.html