非定制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. free函数使用时的注意事项。

    free函数是我们在写C语言程序时常用的函数,但是使用时需要注意,一不小心很肯能会引起吐核. 注意:free函数与malloc()函数配对使用,malloc函数释放申请的动态内存.对于free(p)这 ...

  2. Druid连接池(四)

    十七.Druid加密 运维和DBA都不希望把密码明文直接写在配置文件中,Druid提供了数据库密码加密的功能. ConfigFilter的作用包括: 从配置文件中读取配置 从远程http文件中读取配置 ...

  3. 遇见CUBA CLI

    原文:Meet CLI for CUBA Platform 翻译:CUBA China CUBA-Platform 官网 : https://www.cuba-platform.com CUBA Ch ...

  4. c# winform项目用到的部分知识点总结

    项目用到的知识点总结,欢迎大家吐槽: /// <summary> /// 转换非yyyy-MM-dd的字符串为DateTime类型 /// </summary> public ...

  5. linux的文件基本属性

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

  6. ios app真正的相互!!调用

    1.需求:A应用打开B.B回跳到A   2.问题: 看到网络上的文档讲的大多数都是app单向跳转的例子,而我们在跳转到第二个app的时候往往需要返回到原来的app,虽然支付宝微信等第三方等应用会有回调 ...

  7. 【原】Shiro框架基础搭建[2]

    简介: 关于搭建一个最基础的shiro网上的例子有很多,这里是记录一下自己尝试去看官方文档所搭建的一个小demo,项目采用的是原始的java静态工程,导入相关jar包后就能运行. 首先进入官网http ...

  8. JPA注解@GeneratedValue

    @GeneratedValue是JPA的标准用法, JPA提供四种标准用法,由@GeneratedValue的源代码可以看出. public enum GenerationType { TABLE, ...

  9. Docker(一):入门教程

    2013年发布至今, Docker 一直广受瞩目,被认为可能会改变软件行业. 但是,许多人并不清楚 Docker 到底是什么,要解决什么问题,好处又在哪里?本文就来详细解释,帮助大家理解它,还带有简单 ...

  10. [翻译]Review——24 tips for React Native you probably want to know

    Post author: Albert Gao Post link: http://www.albertgao.xyz/2018/05/30/24-tips-for-react-native-you- ...