非定制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. SharePoint 2013创建应用程序时IIS端口文件夹下没文件

    最近SharePoint 2007迁移到2013的时候,碰到创建应用程序时IIS端口文件夹下没文件的问题,网上找了大把的原因,终于在这里找到了解决方案: Fix: 1. Open IIS on the ...

  2. CC2530自动安全联网

    CC2530自动联网的苦恼 不知道博客园里面有没有人研究CC2530,也就是zigbee技术,其实我在做东西的时候很纠结一个问题,那就是我如何将设备连上后,如何通过协调者发送命令给终端呢?有什么方法可 ...

  3. RabbitMQ上手记录–part 3-发送消息

    接上一part<<RabbitMQ上手记录–part 2 - 安装RabbitMQ>>,这里我们来看看如何通过代码实现对RabbitMQ的调用. RabbitMQ通常是安装在服 ...

  4. 高云的jQuery源码分析笔记

    (function( window, undefined ) { // 构造jQuery对象 var jQuery = function( selector, context ) { return n ...

  5. linux的文件基本属性

    Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规定 1.在Linux中我们 ...

  6. C# 小软件部分(二)

     此次又新增了一些新的功能,直接接着上次的介绍吧 上次博客介绍地址:http://www.cnblogs.com/Liyuting/p/8540592.html 这次新增了三个功能,具体如下: 一.网 ...

  7. COM线程模型的行为

    原文:https://msdn.microsoft.com/library/ms809971.aspx Behavior of the COM Threading Models COM线程模型的行为 ...

  8. 转载:Remote Validation

    http://www.jb51.net/article/89474.htm 大多数的开发者,可能会遇到这样的情况:当我们在创建用户之前,有必要去检查是否数据库中已经存在相同名字的用户.换句话说就是,我 ...

  9. 撩课-Web大前端每天5道面试题-Day17

    1.apply, call和bind有什么区别? 三者都可以把一个函数应用到其他对象上,注意不是自身对象. apply,call是直接执行函数调用,bind是绑定,执行需要再次调用. apply和ca ...

  10. JSP基础知识点

    JSP(Java Server Page)是主要有Sun公司倡导的一种动态网页技术,利用JSP可以构建跨平台的动态网站 应用,JSP在服务器端带JSP容器的Web服务器中运行.JSP以Java语言为基 ...