美文网首页程序员iOS DeveloperiOS开发
iOS笔记-UIImagePickerController使用小

iOS笔记-UIImagePickerController使用小

作者: Developer_Yancy | 来源:发表于2016-04-11 01:49 被阅读1273次

    弹出UIImagePickerController(照片选择器)

    • 如何进入系统的相册UIImagePickerController?

      • 1.创建一个照片选择控制器
        UIImagePickerController *imagePickerVc = [[UIImagePickerController alloc] init];
      • 2.设置数据源(弹出的是否直接是照片库)
        imagePickerVc.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
      • 3.设置代理(UIImagePickerControllerDelegate)
        imagePickerVc.delegate = self;
      • 4.把图片库Modal出来
        [self presentViewController:imagePickerVc animated:YES completion:nil];
    • 如何监听并处理弹出来照片库的点击事件?

      • 1.遵守代理协议
        @interface ViewController ()< UIImagePickerControllerDelegate>
      • 2.设置代理为self
        imagePickerVc.delegate = self;
      • 3.实现代理方法
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        // 获取用户选择照片
        UIImage *image = info[UIImagePickerControllerOriginalImage];
    
        //把Modal出来的imagePickerController弹出
        [self dismissViewControllerAnimated:YES completion:nil];
    
        // 在此处理图片
    }
    

    相关文章

      网友评论

        本文标题:iOS笔记-UIImagePickerController使用小

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