原创blog,转载请注明出处
blog.csdn.net/hello_hwc
前言:
本来要更新NSURLSession的UploadTask的,结果写那个Demo的时候想要写成拍照上传,然后就想到先写一个关于拍照的Demo吧。本文会先介绍下如何使用系统提供的界面拍照和选择相册,然后自定义拍照界面。注意,本文使用的是UIImagePickerController,所以不能完全的自定义,如果想要彻底的自定义拍照,建议选择AV Foundation这个框架来做
Demo效果
进入系统的拍照界面
进入自定义拍照界面
自定义前置摄像头和后置摄像头切换动画-翻页
一 使用系统提供的界面拍照和相册选择
第一步
保存一个UIImagePickerController的实例,然后适当的时候初始化始化。Demo选择在viewDidLoad初始化。让当前类实现UIImagePickerControllerDelegate,UINavigationControllerDelegate两个代理
@property (strong,nonatomic)UIImagePickerController * imagePikerViewController;
//初始化
self.imagePikerViewController = [[UIImagePickerController alloc] init];
self.imagePikerViewController.delegate = self;//通过代理来传递拍照的图片
self.imagePikerViewController.allowsEditing = YES;//允许编辑
第二步,通过ActionSheet来让用户选择是拍照还是到相册选择,然后模态的显示
[self presentViewController:self.imagePikerViewController animated:YES completion:NULL];
注意,要先判断相机是否可用,然后在进入相机(有可能相机坏了,或者在虚拟机上运行的)
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: nil