UIImagePickerController和UIAlertController结合使用
在处理个人资料 - 头像的时候,通常有两个选项,一个是调用系统相机,一个是调用系统相册。这里要使用的就是UIImagePickerController方法。
在头像位置的imageView添加一个手势,或者添加一个透明的按钮,用来实现click方法,直接上代码:
- (IBAction)click:(id)sender{
//创建提醒视图
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提醒" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
//判断设备是否存在摄像头,有就调用系统相机,没有,就提醒用户
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
//创建相机
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//文件由来
picker.sourceType = UIImagePickerControllerSourceTypeCamera; //指定数据来源来自于相机
picker.delegate = self;// 指定代理
picker.allowsEditing = YES; //允许编辑
//模态弹出
[self presentViewController:picker animated:YES completion:nil];
}else{
//没有摄像头,提醒用户 您的设备没有摄像头
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"您的设备没有摄像头" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
[alertController addAction:alertAction1];
[self presentViewController:alertController animated:YES completion:nil];
}
}];
[alertController addAction:alertAction];
UIAlertAction *alertAction2 = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UIImagePickerController *pickerC = [[UIImagePickerController alloc] init];
pickerC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//指定数据来源为相册
pickerC.delegate = self; //指定代理
pickerC.allowsEditing = YES; // 允许编辑
[self presentViewController:pickerC animated:YES completion:nil];
}];
[alertController addAction:alertAction2];
[self presentViewController:alertController animated:YES completion:nil];
}
//选取图片之后执行的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSLog(@"%@",info);
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.photoImage.image = image;
[picker dismissViewControllerAnimated:YES completion:nil];
}
UIImagePickerController和UIAlertController结合使用的更多相关文章
- iOS通过UIAlertController弹出底部选择框来调用相机或者相册
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredSt ...
- iOS8 iPad Warning: Attempt to present <UIImagePickerController:xxxx > on xxxx which is already presenting (null)
解决方法: /* I think this is because in iOS 8, alert views and action sheets are actually presented view ...
- swift2.0 UIImagePickerController 拍照 相册 录像
系统 ios9.1 语言swift2.0 在app 里最常用的功能就是多媒体选择,首先我们storyboard 创建一个button 用于触发选择事件 @IBAction func selectIma ...
- 基于 UIImagePickerController 的拓展封装 - iOS
基于 UIImagePickerController 的拓展,分别支持调用相机.相册的功能,其中相机可以设置默认调用前后摄像头; 简单对此进行了封装和实现,其中还有很多点可以继续挖掘和优化,该版本具体 ...
- iOS8中UIActionSheet弹出UIImagePickerController异常处理
iOS8之后,UIActionSheet改父于UIAlertController.带来了一丢丢兼容性的问题. 比如在弹出的actionsheet中选择从相册选择图片或者拍照,之后弹出UIImagePi ...
- 整理UIImagePickerController问题
[assetsLibrary addAssetsGroupAlbumWithName:@"iOSDevTip1" resultBlock:^(ALAssetsGroup *grou ...
- UIAlertController
楼主在整理项目的警告,于是乎你懂的. 然后自己整理了一下以后方便自己忘了之后能及时找到它 关于UIAlertController .h文件的解析 /** 关于UIAlertController的解析 ...
- iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法
今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...
- UIAlertController使用
// 将UIAlertController模态出来 相当于UIAlertView show 的方法// 初始化一个一个UIAlertController // 参数preferredStyle: ...
随机推荐
- Jquery页面初始化的4种方式
<script src="Scripts/jquery-1.8.2.min.js"></script> <script type="text ...
- Hibernate ManyToOne, OneToMany的理解
User to Group, Many to One的关系 Test Case 1: session.beginTransaction(); user.setGroup(group); session ...
- em详解
最近详细阅读了一下CSS2.2文档,对em单位有了深刻的认识 原文在此:The 'em' unit is equal to the computed value of the 'font-size' ...
- asp.net mvc bundle中数组超出索引
在使用bundle 来加载css的时候报错了, @Styles.Render("~/bundles/appStyles") 第一反应 以为是的css 太多了,可是当我这个style ...
- CentOs6.5下安装svn
1.检查是否已安装 rpm -qa subversion 1.1如果需要卸载旧版本(如果想在一台机器安装不同svn,切记不要执行此步骤!!!) yum remove subversion 2.安装 y ...
- iOS 开发遇到的问题之(nil指针对NSDictionary及NSArray初始化的影响)
nil指针对NSDictionary及NSArray初始化的影响 最近在做项目的时候遇到一个挺坑的崩溃问题,是由于NSDictionary初始化时nil指针引起的崩溃.假设我们现在要初始化一个{key ...
- 【Java】需要注意的小细节
一.==和equals 1.比较两个变量时 a.==可以判断两个变量是否相等,如果两个变量是基本类型变量,而且是数值类型,只要两个变量值相等,返回true. 2.比较两个引用变量 a.==只有两个引用 ...
- angularJS 学习之路
AngularJS 通过 ng-directives 扩展了 HTML. ng-app 指令定义一个 AngularJS 应用程序.也就是angularjs作用的入口 作用在什么标签或者整个body ...
- no route to host
防火墙没有关闭: systemctl stop firewalld
- Oracle之常见问题诊断方法
Oracle认证:常见问题诊断方法如下: 1.TNS-12154 Error 或ORA-12154 特征:SQL*NET没有找到连接串或别名 原因1:(1)没有找到TNSNAMES.ORA文件,该文件 ...