美文网首页
UIImagePickerController总结

UIImagePickerController总结

作者: 超_iOS | 来源:发表于2017-03-21 10:33 被阅读198次

    目前有个问题:用iPad剪裁后的照片选择后,只剩下了左上角一部分.原因不明.还望大神不吝赐教.

    以下内容来自网络,本人总结自看:
    iOS 获取图片有三种方法:

    1. 直接调用摄像头拍照
    2. 从相册中选择
    3. 从图库中选择
    UIImagePickerController 是系统提供的用来获取图片和视频的接口;
    UIImagePickerController 类来获取图片视频,大体分为以下几个步骤:
    
     1. 初始化UIImagePickerController 类;
     2. 设置UIImagePickerController 实例的数据来源类型(下面解释);
     3. 设置设置代理;
     4. 如果需要做图片修改的话设置allowsEditing =yes。
    数据来源类型一共有三种:
    
    enum {
         UIImagePickerControllerSourceTypePhotoLibrary ,//来自图库
         UIImagePickerControllerSourceTypeCamera ,//来自相机
         UIImagePickerControllerSourceTypeSavedPhotosAlbum //来自相册
         };
    获取图片首先签订两个协议
    @interface MainViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
    在点击方法内模态推出UIImagePickerController
    从相册选取(需给用户选择哪种方式获取图片)
    //sourceType 是用来确认用户界面样式,选择相册
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    //设置代理
    imagePicker.delegate = self;
    //允许编辑弹框
    imagePicker.allowsEditing = YES;
    //是用手机相册来获取图片的
    imagePicker.sourceType = sourceType;      
    //模态推出pickViewController
    [self presentViewController:imagePicker animated:YES completion:nil];
    从相机获取
    //sourceType 是用来确认用户界面的样式, 选择相机
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    //设置代理
    imagePicker.delegate = self;
    //允许编辑弹框
    imagePicker.allowsEditing = YES;
    //是用相机照相来获取图片
    imagePicker.sourceType = sourceType;
    //模态推出pickViewController
    [self presentViewController:imagePicker animated:YES completion:nil];
    实现代理方法
    //选择完图片后会回调 didFinishPickingMediaWithInfo 这个方法
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    NSLog(@"info = %@",info);
    //隐藏控制器
      [picker dismissViewControllerAnimated:YES completion:nil];
    //给imageView 赋值图片
      imageView.image = [infoobjectForKey:UIImagePickerControllerEditedImage];
    }
    //导航条上面的 Cancel 的点击方法
    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    //隐藏控制器
      [picker dismissViewControllerAnimated:YES completion:nil];
    }
    

    来自:http://www.jianshu.com/p/fd4b4407dff0

    iOS开发中,我们经常遇到获取拍照、相册中图片的功能,就必然少不了UIImagePickerController,但是我们发现当我们使用它的时候,它的页面是英文的,看着很别扭,国人还是比较喜欢看中文界面,下面来看看我们怎么把它变成中文界面的吧!
    只需下面两步就可以了:
    Project-->Info-->Localizations 添加 Chinese

    Mou icon

    Target-->Info-->Localization native development region 值修改为 China

    Mou icon

    科普一下:以前xcode3生成的项目,修改Target-->Info-->Localization native development region 的值为China就能显示中文;Xcode4以后修改Target-->Info-->Localization native development region值为China还不够,同时还需要设置Project-->info-->Localizations Language添加Chinese才行。

    来自:http://www.jianshu.com/p/6ce6e293b268

    相关文章

      网友评论

          本文标题:UIImagePickerController总结

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