创建图片

#pragma mark - 创建 photoImageView
- (void)createphotoImageView
{ self.photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 70, 320, 390)];
self.photoImageView.backgroundColor = [UIColor magentaColor]; // 打开交互 实现手势轻拍
self.photoImageView.userInteractionEnabled = YES; [self addSubview:self.photoImageView];
}

实现代理(3个)

@interface RootViewController () <UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
// 绑定手势
- (void)viewDidLoad {
[super viewDidLoad]; // 轻拍手势
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)]; [self.rootView.photoImageView addGestureRecognizer:tapGR]; }
#pragma mark - 实现手势操作
- (void)tapGRAction:(UITapGestureRecognizer *)sender
{
NSLog(@"tap it"); // 底部弹出的控件
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请选择图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相冊选取",@"拍照", nil]; // 在什么地方展示
[sheet showInView:self.rootView];
}
#pragma mark - 轻拍手势中 action 代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld", buttonIndex); // 从相冊选取或拍照
if (actionSheet.firstOtherButtonIndex == buttonIndex) {
NSLog(@"相冊"); // 相冊是否可用
if ([UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypePhotoLibrary)]) { UIImagePickerController *imagePickerVC = [[UIImagePickerController alloc] init]; // 通过代理方法拿到图片
imagePickerVC.delegate = self;
// 能够对图片进行编辑(相应代理方法)
imagePickerVC.allowsEditing = YES; // 指定 pickVC 从相冊选取
imagePickerVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; // 模态推出
[self presentViewController:imagePickerVC animated:YES completion:nil];
} } else if (buttonIndex == actionSheet.firstOtherButtonIndex + 1)
{
NSLog(@"拍照"); if ([UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypeCamera)]) { UIImagePickerController *imagePickerVC = [[UIImagePickerController alloc] init]; // 通过代理方法拿到图片
imagePickerVC.delegate = self;
// 能够对图片进行编辑(相应代理方法)
imagePickerVC.allowsEditing = YES; // 指定 pickVC 从相机选取
imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera; // 模态推出
[self presentViewController:imagePickerVC animated:YES completion:nil];
}
}
}
#pragma mark - 实现代理方法(拿到图片)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil]; UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; self.rootView.photoImageView.image = image;
}
#pragma mark - 取消按钮的代理方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
// 一般在 rightButton
[picker dismissViewControllerAnimated:YES completion:nil];
}

UI_UIImagePickerController(读取图片)的更多相关文章

  1. nodejs进阶(4)—读取图片到页面

    我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...

  2. HTML中上传与读取图片或文件(input file)----在路上(25)

    input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...

  3. nodeJS基础08:读取图片

    1.读取图片 //server.js var http = require("http"); var readImage = require("./readImage&q ...

  4. opencv用imread( argv[1], 1)读取图片

    显示一幅图:主要是运用功能:imread namedWindow imshowimread:从字面意思我们就可以看懂,用来读取图片的:namedWindow:显然,我们也可以看到这是用来命名窗口名称的 ...

  5. Servlet从本地文件中读取图片,并显示在页面中

    import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...

  6. [OpenCV] 1、读取图片

    >_<" 安装及配置请看http://www.cnblogs.com/zjutlitao/p/4042074.html >_<" 这篇是一个简单的在VS20 ...

  7. [转]asp.net mvc 从数据库中读取图片

    本文转自:http://www.cnblogs.com/mayt/archive/2010/05/20/1740358.html 首先是创建一个类,继承于ActionResult,记住要引用Syste ...

  8. asp.net mvc 从数据库中读取图片的实现代码

    首先是创建一个类,继承于ActionResult,记住要引用System.Web.Mvc命名空间,如下: public class ImageResult : ActionResult { publi ...

  9. 最蛋疼的bug:读取图片缩略图(一定要在相冊查看下形成缓存)

    近期的一个连接服务端的应用.须要读取图片,一般供用户公布商品选择上传图片.初始的图片列表应该是缩略图.仅仅有确定了,才上传原图,OK不多说上代码 package edu.buaa.erhuo; imp ...

  10. C#(WinForm)上传图片保存到数据库和从数据库读取图片显示到窗体

    //浏览图片 private void btnUp_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialo ...

随机推荐

  1. Java - 经常使用函数Random函数

    http://blog.csdn.net/pipisorry/article/details/44411541 Random()函数生成随机数 java.util.Random 在Java的API帮助 ...

  2. ios OpenCv的配置和人脸识别技术

    作为一个好奇心非常重的人,面对未知的世界都想去一探到底. 于是做了个人脸识别的demo. 眼下国内的关于opencv技术文章非常少.都是互相抄袭.关键是抄个一小部分还不全.时间又是非常久之前的了,和如 ...

  3. LayoutParams继承于Android.View.ViewGroup.LayoutParams.

    LayoutParams相当于一个Layout的信息包,它封装了Layout的位置.高.宽等信息.假设在屏幕上一块区域是由一个Layout占领的,如果将一个View添加到一个Layout中,最好告诉L ...

  4. kentico中提示Message: An invalid SQL query was used.

    在调用CMSAbstractWebPart类的GetValue方法的时候出错. namespace CMS.PortalEngine.Web.UI{ /// <summary> /// B ...

  5. WebService中使用自定义类的解决方法(5种)

    转自:http://www.cnblogs.com/lxinxuan/archive/2007/05/24/758317.html Demo下载:http://files.cnblogs.com/lx ...

  6. JSP页面动态查询添加数据与分页数据显示

    1 . <%@ page language="java" contentType="text/html; charset=UTF-8"%> < ...

  7. CSS中alt和title属性的正确使用

    1.在<img>标签中的使用 alt:全称为alttext,实质是当图片无法正确显示时用于替换(在IE下同时起到了title的作用,即鼠标滑过时文字提示): title:鼠标经过时文字提示 ...

  8. c++面向对象程序设计 课后题 答案 谭浩强 第四章

    c++面向对象程序设计课后题答案 谭浩强 第四章 1: #include <iostream> using namespace std; class Complex {public: Co ...

  9. Python学习小计

    1.初学Python最好选择2.7版本,因为大部分Python书籍的示例代码是基于这个版本的 2.Python安装可以参考百度经验完成 如果在电脑上同时安装2个版本,则CMD启动时只需要: py -2 ...

  10. Ztree自动触发第一个节点的点击事件

    1.代码 $(function () { var setting = { //check属性放在data属性之后,复选框不起作用 //check: { // enable: true //}, dat ...