照相/图片库
来源:互联网 发布:bl漫画肉软件 编辑:程序博客网 时间:2024/05/02 00:26
UIImagePickerController是图片控制器,需要继承UIImagePickerControllerDelegate,UINavigationControllerDelegate代理
点击拍照按钮,模态弹出UIAlertController控制器类,代码如下:
- (void)onCamera{ //常用控件 //UIAlertView 警告视图 (iOS 8.0以前) //UIActionSheet (iOS 8.0以前) //UIAlertController (iOS 8.0以后) UIAlertController *ac = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; //添加第一个Action,从图片库选择照片 [ac addAction:[UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self loadImagePicker:UIImagePickerControllerSourceTypePhotoLibrary]; }]]; //添加第二个Action,拍照 [ac addAction:[UIAlertAction actionWithTitle:@"照相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self loadImagePicker:UIImagePickerControllerSourceTypeCamera]; }]]; //添加第三个Action,取消 [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]]; //显示页面 [self presentViewController:ac animated:YES completion:nil];}
弹出图片控制器
- (void)loadImagePicker:(UIImagePickerControllerSourceType)type{ //首先,判断soureType 是否可用 if ([UIImagePickerController isSourceTypeAvailable:type]) { //创建UIImagePickerController对象 UIImagePickerController *pickerContr = [[UIImagePickerController alloc] init]; //设置属性 pickerContr.sourceType = type; //设置代理 pickerContr.delegate = self; //显示imagePicker控制器 [self presentViewController:pickerContr animated:YES completion:nil]; }else { NSLog(@"source type is not available , type = %ld",type); }}
两个代理方法
#pragma mark - 代理方法- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ //返回上一个页面,关闭当前页面 [picker dismissViewControllerAnimated:YES completion:nil];}- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ //info 存储选择的图片 UIImage *img = info[UIImagePickerControllerOriginalImage]; self.iv.image = img; //关闭页面 [picker dismissViewControllerAnimated:YES completion:nil];}
0 0
- 照相/图片库
- i os 照相 图片库
- 图片库
- 图片库
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS 实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS---头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像 (转)
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- 照相
- ElasticSearch学习2_Java version:1.7.0_51 suffers from critical bug及ES对JDK版本要求
- UEFI&GPT VS BIOS&MBR
- 关于全排列的总结
- 第9章 子窗口控件
- Linux 精萃
- 照相/图片库
- Spring--quartz中cronExpression配置说明 (注意?说明)
- 书是进入另一个世界的门径--5篇最近阅读好书的短评
- 如何将一个uiview推送到窗口的前面与背后
- PHP 性能分析第三篇: 性能调优实战
- MySql 5.6.20,安装后无法登陆的解决办法
- 深入理解Tagged Pointer
- Java中的享元(flyweight)设计模式
- Flash中启动Linux的方法