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: ...
随机推荐
- c# 根据配置文件路径,设置和获取config文件 appSettings 节点值
/// <summary> /// 获取编译后的主配置文件节点值 /// </summary> /// <param name="key">&l ...
- 数据源增量处理(Delta Proess)三大属性:Recod Mode、Delta Type、Serialization
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- TensorFlow支持windows了
(留坑)找个时间测试一下. 终于来了,TensorFlow 新增官方 Windows 支持
- Making my own Autonomous Robot in ROS / Gazebo, Day 2: Enable the robot
Day 2: Enable the robot Git Setting git checkout master git branch day2_enable_robot git push --set- ...
- iOS - MKMapView 地图
1.创建 MKMapView 地图 在 iOS6 或者 iOS7 中实现这个功能只需要添加地图控件.设置用户跟踪模式.在 mapView:didUpdateUserLocation: 代理方法中设置地 ...
- Deep Learning 22:总结一些deep learning的基本知识
1.交叉熵代价函数 2.正则化方法:L1和L2 regularization.数据集扩增.dropout 3. 数据预处理 4.机器学习算法中如何选取超参数:学习速率.正则项系数.minibatch ...
- PHP 文件的操作
操作文件的步骤: 1.打开文件2.做操作PS!!!3.关闭文件 打开 操作
- Python之路 day2 字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...
- 0.读书笔记之The major advancements in Deep Learning in 2016
The major advancements in Deep Learning in 2016 地址:https://tryolabs.com/blog/2016/12/06/major-advanc ...