非定制UIImagePickerController的使用

效果:

源码:

//
// ViewController.m
// ImagePic
//
// Created by XianMingYou on 15/3/26.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "ViewController.h" typedef enum : NSUInteger {
TAKE_IMAGE,
TAKE_PHOTO,
} EChooseFlag; @interface ViewController ()<UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UIImageView *showImageView;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; [self.view addSubview:self.showImageView];
[self.view addSubview:self.button];
} // 照片
@synthesize showImageView = _showImageView;
- (UIImageView *)showImageView {
if (_showImageView == nil) {
_showImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
_showImageView.layer.masksToBounds = YES;
_showImageView.contentMode = UIViewContentModeScaleAspectFill;
} return _showImageView;
} // 按钮
@synthesize button = _button;
- (UIButton *)button {
if (_button == nil) { CGRect rect = self.view.bounds;
CGFloat height = rect.size.height;
CGFloat width = rect.size.width; _button = [[UIButton alloc] initWithFrame:CGRectMake(, height - , width, )];
[_button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
[_button setTitle:@"Take" forState:UIControlStateNormal];
[_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_button.backgroundColor = [UIColor blackColor];
} return _button;
} - (void)buttonEvent:(id)sender {
[self initActionSheet];
} // ActionSheet
- (void)initActionSheet {
UIActionSheet *pickerActionSheet = \
[[UIActionSheet alloc] initWithTitle:@"选择"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"获取系统相册", @"拍照", nil];
[pickerActionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == TAKE_IMAGE) {
[self takeImage];
} else if (buttonIndex == TAKE_PHOTO) {
[self takePhoto];
} else { }
} // 获取图片控制器
- (void)takeImage {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.view.backgroundColor = [UIColor whiteColor];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; /*
UIImagePickerControllerSourceTypePhotoLibrary 文件夹管理形式
UIImagePickerControllerSourceTypeSavedPhotosAlbum 显示所有文件形式
*/ [self presentController:imagePicker];
} // 获取图片控制器
- (void)takePhoto {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.view.backgroundColor = [UIColor whiteColor];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentController:imagePicker];
} // 图片控制器代理
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerOriginalImage];
if (image) {
self.showImageView.image = image;
[self dismissController:picker];
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissController:picker];
} - (void)dismissController:(UIViewController *)controller {
[controller dismissViewControllerAnimated:YES completion:^{}];
}
- (void)presentController:(UIViewController *)controller {
[self presentViewController:controller animated:YES completion:^{}];
} @end

一些小细节:

实现两个代理方法:

非定制UIImagePickerController的使用的更多相关文章

  1. poscms用法总结(非定制开发,不涉及后台代码)

    这些天几个企业站仿下来,对poscms的用法多少有些了解了,在这个记录一下,好记性不如烂笔头嘛. 1.静态文件目录和模板文件目录 这两个目录分别放置css/js/image等静态文件和html模板文件 ...

  2. Apple、Google、Microsoft的用户体验设计原则

    轻巧的Apple 注重设计过程: 在设计过程中引入用户交互的5个目标: 了解您的目标客户 分析用户的工作流 构造原型系统 观察用户测试 制定观察用户准则 做出设计决定 避免功能泛滥 80% 方案 优秀 ...

  3. 【资源】HTML5工具篇:10个营销人也能轻松使用的在线编辑平台

    一 3, 2015 in 资源 作者:Teeya 2014年,HTML5 页面作为营销界新宠儿,“多快好省”的杰出代表,其灵活性高.开发成本低且制作周期短的种种特性使其在移动营销领域大放异彩. 此前, ...

  4. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q75-Q77)

    Question 75You are designing a feature for a SharePoint 2010 solution that will be activated by defa ...

  5. BI项目需求分析书-模板

    目录 目录 .............................................................................................. ...

  6. 怎样做出优秀的扁平化设计风格 PPT 或 Keynote 幻灯片演示文稿?(装)

    不知道你有没有想过,为什么很人多的扁平化 PPT 是这个样子: 或者是这样: 然而,还有一小撮人的扁平化 PPT 却拥有那么高颜值: 为什么会产生这么大的差距呢?丑逼 PPT 应该如何逆袭成为帅逼呢? ...

  7. Android app security安全问题总结

    数据泄漏 本地文件敏感数据不能明文保存,不能伪加密(Base64,自定义算法等) android:allowbackup=false. 防止 adb backup 导出数据 Activity inte ...

  8. hp MSA50 5盘RAID5重建为4盘RAID5怎么恢复数据

    [用户单位] XX省电视台[数据恢复故障描述] 一台HP 服务器,挂接一台HP MSA50磁盘阵列,内接5块1TB硬盘,原先结构为RAID5. 使用一段时间后,其中一块硬盘掉线,因RAID5支持一块硬 ...

  9. 6块300G SCSI RAID5,两块硬盘损坏的数据恢复总结

    [用户单位]XXXX网站[数据恢复故障描述]DELL POWEREDGE 2850服务器,内置6块300G SCSI硬盘 ,组成RAID5,安装LINUX REDHAT 4操作系统,存储大量照片,文件 ...

随机推荐

  1. 梯度下降法的三种形式-BGD、SGD、MBGD

    在应用机器学习算法时,我们通常采用梯度下降法来对采用的算法进行训练.其实,常用的梯度下降法还具体包含有三种不同的形式,它们也各自有着不同的优缺点. 下面我们以线性回归算法来对三种梯度下降法进行比较. ...

  2. NLP 装桶(Bucketing)和填充(padding)

    翻译模型也是用了装桶(bucketing)和填充(padding),这两种方法是用于高效地处理不同长度句子的情况.我们首先来弄清楚是怎么一回事.当我们从英语翻译成法语的时候,假设我们的输入英语的长度为 ...

  3. SpringBoot入门 (六) 数据库访问之Mybatis

    本文记录学习在SpringBoot中使用Mybatis. 一 什么是Mybatis MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 ...

  4. vim---打造Python IDE

    1.文法高亮 为了能在Vim中支持Python文法需要用到插件python.vim,该插件默认位于(/usr/share/vim/vim72/)<Vim安装目录>/<$VIMRUNT ...

  5. [IMX6]Android6.0移植和分析

    0. 知识点 中断(设备树) [IMX6]设备树分析--dts 1. 编译 Android6.0内核移植(1):分析编译日志 Android6.0内核移植(2):kernel编译内核 单独烧录kern ...

  6. Django 多表查询

    多表查询是模型层的重要功能之一, Django提供了一套基于关联字段独特的解决方案. ForeignKey 来自Django官方文档的模型示例: from django.db import model ...

  7. orcle查询记录的每天的第一条

    select * from (      select elec,time,Row_Number() OVER (partition by trunc(TIME) order by time) ran ...

  8. ionic中generate page后module.ts报错的解决办法

    此问题出现在Ionic官方将版本从2.2升级到Ionic3以上之后, 在项目中generate page时,自动创建的module.ts就报错,如下: 解决办法如下: 1)将IonicModule替换 ...

  9. 使用jQuery和CSS3制作数字时钟(jQuery篇) 附源码下载

    HTML 和上一篇文章:使用jQuery和CSS3制作数字时钟(CSS3篇)一样的HTML结构,只是多了个>date用来展示日期和星期的. <div id="clock" ...

  10. Q:链表的倒数第K个元素

    问题:如何得到链表中的倒数第k个元素?   一种简单的思路是遍历链表一遍,并统计出链表中节点的数目,然后计算出倒数第k个元素到链表头节点的元素的距离,然后得到对应的结果.但是,我们能否有一种更加简便的 ...