非定制UIImagePickerController的使用
非定制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的使用的更多相关文章
- poscms用法总结(非定制开发,不涉及后台代码)
这些天几个企业站仿下来,对poscms的用法多少有些了解了,在这个记录一下,好记性不如烂笔头嘛. 1.静态文件目录和模板文件目录 这两个目录分别放置css/js/image等静态文件和html模板文件 ...
- Apple、Google、Microsoft的用户体验设计原则
轻巧的Apple 注重设计过程: 在设计过程中引入用户交互的5个目标: 了解您的目标客户 分析用户的工作流 构造原型系统 观察用户测试 制定观察用户准则 做出设计决定 避免功能泛滥 80% 方案 优秀 ...
- 【资源】HTML5工具篇:10个营销人也能轻松使用的在线编辑平台
一 3, 2015 in 资源 作者:Teeya 2014年,HTML5 页面作为营销界新宠儿,“多快好省”的杰出代表,其灵活性高.开发成本低且制作周期短的种种特性使其在移动营销领域大放异彩. 此前, ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q75-Q77)
Question 75You are designing a feature for a SharePoint 2010 solution that will be activated by defa ...
- BI项目需求分析书-模板
目录 目录 .............................................................................................. ...
- 怎样做出优秀的扁平化设计风格 PPT 或 Keynote 幻灯片演示文稿?(装)
不知道你有没有想过,为什么很人多的扁平化 PPT 是这个样子: 或者是这样: 然而,还有一小撮人的扁平化 PPT 却拥有那么高颜值: 为什么会产生这么大的差距呢?丑逼 PPT 应该如何逆袭成为帅逼呢? ...
- Android app security安全问题总结
数据泄漏 本地文件敏感数据不能明文保存,不能伪加密(Base64,自定义算法等) android:allowbackup=false. 防止 adb backup 导出数据 Activity inte ...
- hp MSA50 5盘RAID5重建为4盘RAID5怎么恢复数据
[用户单位] XX省电视台[数据恢复故障描述] 一台HP 服务器,挂接一台HP MSA50磁盘阵列,内接5块1TB硬盘,原先结构为RAID5. 使用一段时间后,其中一块硬盘掉线,因RAID5支持一块硬 ...
- 6块300G SCSI RAID5,两块硬盘损坏的数据恢复总结
[用户单位]XXXX网站[数据恢复故障描述]DELL POWEREDGE 2850服务器,内置6块300G SCSI硬盘 ,组成RAID5,安装LINUX REDHAT 4操作系统,存储大量照片,文件 ...
随机推荐
- MySQL命令行导入导出数据
参考:http://www.cnblogs.com/xcxc/archive/2013/01/30/2882840.html 这篇文章写得非常好,又简洁,而且深入浅出,排版也非常好看,不会像网上的只是 ...
- java.io.Serializable的作用
Serializable,之前一直有使用,默认的实体类就会实现Serializable接口,对具体原因一直不是很了解,同时如果没有实现序列化,同样没什么影响,什么时候应该进行序列化操作呢?今天查了下资 ...
- Memcached理解笔记4---应对高并发攻击
近半个月过得很痛苦,主要是产品上线后,引来无数机器用户恶意攻击,不停的刷新产品各个服务入口,制造垃圾数据,消耗资源.他们的最好成绩,1秒钟可以并发6次,赶在Database入库前,Cache进行Mis ...
- Deep Q-Network 学习笔记(五)—— 改进③:Prioritized Replay 算法
也就是优先采样,这里的推导部分完全没看懂 Orz,这里也只是记录实现代码. 也就是看了以下两篇文章对应做了实现. 莫烦老师的教程: https://morvanzhou.github.io/tutor ...
- (一)面向对象的javascript
javascript是一门典型的动态类语言 一:鸭式辨型(指导我们关注对象的行为,而不关注对象本身). var duck = { duckString: function(){ console.log ...
- nuget.org 无法加载源 https://api.nuget.org/v3/index.json 的服务索引
今天添加新项目想添加几个工具包,打开NuGet就这样了 发生错误如下: [nuget.org] 无法加载源 https://api.nuget.org/v3/index.json 的服务索引. 响应 ...
- 【原】使用Maven完成自动化打包并部署到Linux服务器下(Tomcat7)
最近在使用maven,顺便尝试了下tomcat部署.网上找到了很多资料但是都不是最新的,所以贴上比较新的Tomcat7部署代码和配置,方便以后回顾-->测试OK. 1. 首先是配置Tomcat ...
- K:伸展树(splay tree)
伸展树(Splay Tree),也叫分裂树,是一种二叉排序树,它能在O(lgN)内完成插入.查找和删除操作.在伸展树上的一般操作都基于伸展操作:假设想要对一个二叉查找树执行一系列的查找操作,为了使 ...
- druapl7:"Notice: A non well formed numeric value encountered 在 _hierarchical_select_hierarchy_generate() "
这个是很诡异的一个Notice错误提醒,因为我在Drupal7.54+PHP7.0.1的环境下,并没有报这个错.但是我再Drupal7.59+PHP7.1.7的环境下就报错了.很奇怪,按照报错信息bi ...
- 关于ie7下display:inline-block;不支持的解决方案
关于ie7下display:inline-block:不支持的解决方案 今天码的时候遇到这个问题了. 如果本身是内联元素的,把它的display属性设置设置为inline-block时,所有浏览器都是 ...