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: ...
随机推荐
- 准备阶段-maven项目构建
依据我现阶段对maven的了解,具使用POM管理项目和强大的repository资源管理库支持. 在项目建立初期,对网站的可拓展.高并发.易于管理做了评估.最终使用Maven 管理该项目 . 如下是m ...
- [bzoj3192][JLOI2013]删除物品(树状数组)
3192: [JLOI2013]删除物品 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 872 Solved: 508[Submit][Status ...
- 最新榜单!消金企业TOP10,数据、风控、催收服务方TOP5
最新榜单!消金企业TOP10,数据.风控.催收服务方TOP5 布谷TIME2016-12-15 17:47:59消费 风控阅读(164)评论(0) 声明:本文由入驻搜狐公众平台的作者撰写,除搜狐官方账 ...
- jQuery 查找父元素
function deletesec1Div5(obj){ $(obj).closest(".sec1-div5").remove();}自己写的一段代码,实现了table中的全选 ...
- Linux 常见问题解决办法
1.用户切换后显示 -bash-4.1 $ 表示该用户下的配置文件缺失,切换到该用户下(-bash-4.1),使用命令查(pwd)看用户所在位置.如 /home/gpadmin. 使用 cp -a / ...
- 在控制台启动服务器时出现:对于服务器soa1_wls, 与计算机oim1相关联的节点管理器无法访问。
问题:在控制台启动服务器时出现:对于服务器soa1_wls, 与计算机oim1相关联的节点管理器无法访问.原因:nodemanager没有启起来解决方法: 一.对于managedServer于admi ...
- 转:OSGi 入门篇:模块层
OSGi 入门篇:模块层 1 什么是模块化 模块层是OSGi框架中最基础的一部分,其中Java的模块化特性在这一层得到了很好的实现.但是这种实现与Java本身现有的一些模块化特性又有明显的不同. 本文 ...
- easyui layout 布局title
<script> function aclick(){ $("a").click(function () { var name=this.innerHTML; $($( ...
- Oracle转MySQL
1. to_date 直接去掉 例如 select log.id from CM_LOGINLOG log where log.orgid =? and log.isAuto =? and lo ...
- 关于《hibernate多对多》有中间表的建立
角色 与 菜单(资源)的多对多关系,在这里我们建立中间表,用两个oneToMany实现 实体类: 角色(GmRole) 菜单(GmMenu) 中间表(GmRoleRight) 1.在角色实体中 pa ...