引入框架:

#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>

实现代理:

UIImagePickerControllerDelegate

建一个imageView,并为它添加一个点击事件

 _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];_imageView.backgroundColor = [UIColor grayColor];_imageView.userInteractionEnabled = YES;[self.view addSubview: _imageView];UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singerTap:)];[_imageView addGestureRecognizer:tap];

点击事件响应函数:

- (void)singerTap:(UITapGestureRecognizer *)gesture {//UIAlertControllerStyleActionSheet弹窗在屏幕下面UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"选取图片" message:nil preferredStyle: UIAlertControllerStyleActionSheet];UIAlertAction *cameraAction=[UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {//点语法self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;self->_imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;self->_imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;//录制视频时长,默认10sself->_imagePickerController.videoMaximumDuration = 15;//相机类型(拍照、录像...)字符串需要做相应的类型转换self->_imagePickerController.mediaTypes = @[(NSString *)kUTTypeMovie,(NSString *)kUTTypeImage];//视频上传质量//UIImagePickerControllerQualityTypeHigh高清//UIImagePickerControllerQualityTypeMedium中等质量//UIImagePickerControllerQualityTypeLow低质量//UIImagePickerControllerQualityType640x480self->_imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;//设置摄像头模式(拍照,录制视频)为录像模式self->_imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;[self presentViewController:self->_imagePickerController animated:YES completion:nil];}];UIAlertAction *photosAlbumAction=[UIAlertAction actionWithTitle:@"图片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {//点语法self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;self->_imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;[self presentViewController:self->_imagePickerController animated:YES completion:nil];}];UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self dismissViewControllerAnimated:YES completion:nil];}];//判断是否支持相机if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {[alert addAction:cameraAction];}[alert addAction:photosAlbumAction];[alert addAction:cancelAction];[self presentViewController:alert animated:YES completion:nil];
}

选取后回调函数:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {[picker dismissViewControllerAnimated:YES completion:nil];//原始照片
//    _imageView.image = [info objectForKey: UIImagePickerControllerOriginalImage];//编辑后照片_imageView.image = [info objectForKey: UIImagePickerControllerEditedImage];
}

[iOS开发]iOS调用系统相册相机相关推荐

  1. html5 调用系统相册,iOS之H5调用系统相册相机浏览文件

    在我们iOS开发中大家遇到过H5和原生交互,需要上传文件,刚开始的思路肯定是在之前轻车熟路的js交互中原生方法获取文件之后上传,今天我们了解一个新的方法,其实苹果官方给我们提供了一个更简单的方法, H ...

  2. iOS 开发之调用系统铃声以及震动

    iOS 开发之调用系统铃声以及震动 @interface AlarmClass : NSObject {SystemSoundID soundID; }//调用震动 -(void)systemShak ...

  3. ios ipad里面调用系统相册图片不完整解决方法

    项目里面用到了系统相册,在手机里面取出来是完整的,但是在pad里面取出来就是不完整,只是取到左上角的一部分,开始查资料,最后的解决办法是,在调UIImagePickerController这个类时将这 ...

  4. iOS——调用系统相册和相机

    iOS--调用系统相册和相机 背景 我们在许多app里可以发现在换头像的时候一般有两个选择,一个是选择本地照片,一个选择是相机也就是直接拍一张照片当头像,另外还有就是可以去修改照片尺寸,所以我们就要知 ...

  5. iOS 开发之调用相机

    iOS开发之调用相机 苹果移动设备调用相机功能 项目过程中遇到一个功能需求(调用相机拍照) 第一步 要使用系统相机必须遵守 @interface ImmediateAnswerViewControll ...

  6. iOS 采用@available(iOS 11.0, *)适配 iOS11,会引起调用系统相册时,系统界面上移问题

    我们在使用以下方法适配 iOS11,避免滚动视图顶部出现20的空白以及push或者pop的时候页面有一个上移或者下移的异常动画的问题时,会导致一个问题,就是当我们的应用调用系统相册时,引起系统相册界面 ...

  7. iOS调用系统相册显示英文标题

    调用系统相册.相机,发现是英文的标题"photos",但是手机语言已经设置显示中文,解决办法: 在info.plist里面添加Localized resources can be ...

  8. iOS 调用系统相册拍照时显示英文问题

    在调用系统相册拍照的时候,在选择照片的时候,发现用的都是英文,效果如下: 我们想把那个Retake 和Use Photo 改为对应的汉字,先来一种最笨的方法,最后在来个高级的方法,最笨的办法当然是我们 ...

  9. iOS获取、写入系统相册图片

    ####为什么要调用系统相册 现在很多项目都会用到调用系统相册,例如保存图片到系统相册.选取相册中的图片.给联系人设置头像.聊天时给好友发送照片等.下面就看下如何调取系统相册: ####读取方式 *读 ...

  10. Android调用系统相册、拍照以及裁剪最简单的实现(兼容7.0)

    这里我只实现功能,具体Android 7.0 的一些细节参考 http://blog.csdn.net/lmj623565791/article/details/72859156 具体步骤: 一.在清 ...

最新文章

  1. linux ftp 团队认证,linux下ftp和ftps以及ftp基于mysql虚拟用户认证服务器的搭建
  2. 细数 Windows 平台上的 NoSQL 数据库
  3. React Redux 的一些基本知识点
  4. 上拉电阻和下拉电阻的作用详解
  5. 群晖nas怎么上传整个文件夹_你为什么需要一台NAS(第二期)
  6. 2016.07.17-18 集合方法
  7. 【渝粤教育】国家开放大学2018年春季 建筑结构基础 参考试题
  8. Linux的实际操作:文件目录类的实用指令(重定向“>“和追加“>>“)
  9. 用SSE加速CPU蒙皮计算
  10. 北京思源培训中心---C#下用P2P技术实现点对点聊天(2)
  11. linux中,添加cvs用户,实质就是添加linux用户 (extssh 连接方式)。 (添加时,注意是否要分组。)
  12. hdoj 4526 威威猫系列故事——拼车记
  13. pom文件报错_FastDFS实战总结,分布式文件存储,高并发高可用,看这篇就够了...
  14. component组件基础
  15. “0元送设计”如何换来70亿营收?尚品宅配的新零售数字化增长研究
  16. retina屏下的1px线的实现
  17. php 方差函数,PHP应用:PHP基于方差和标准差计算学生成绩的稳定性示例
  18. php启动后no input file specified.,php网站出现no input file specified 三种解决方法
  19. 南京大学计算机科学专硕培养方案,计算机科学与技术专业硕士研究生培养方案(2014版)...
  20. 201509281125_《为什么移动app会很慢的深度分析(摘自司徒正美博客园文章)》

热门文章

  1. 房聚良源系统功能介绍(SpringBoot)
  2. RealSense 图形识别之路 2.0
  3. leetcode(19):Anagrams (字谜游戏)
  4. Quartus-II入门实战
  5. 内网服务器使用代理上网
  6. 基于单片机的D/A三角波发生器设计(电路+程序)
  7. linux如何卸载光驱显示busy,执行umount 的时候却提示:device is busy 的处理方法 卸载挂载的盘提示如下...
  8. 喝咖啡有什么好处和坏处?
  9. 以撒的结合-重生 n项 修改器
  10. android资源文件assets