iOS9 相册的进入及显示图片
来源:互联网 发布:粤菜菜谱大全软件 编辑:程序博客网 时间:2024/04/29 14:21
最近做添加图片功能,发现网络上 demo 大多时间久远,很多一些代理方法已被 APPLE 弃用 ,所以 写个简单的 进入 相册 的 demo,帮助大家//// ViewController.m// UIImagePickerController//// Created by michael on 15/11/9.// Copyright © 2015年michael. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>@property (nonatomic,strong) UIButton *button;@end@implementation ViewController- (void)viewDidLoad { [superviewDidLoad]; // Do any additional setup after loading the view. //点击进入相册 [self enterPhotosAlubm];}-(void) enterPhotosAlubm{ //添加按钮及相关属性 _button = [[UIButtonalloc] initWithFrame:CGRectMake(0,20, 200,50)]; [_buttonsetTitle:@"进入相册"forState:(UIControlStateNormal)]; [_buttonsetTitleColor:[UIColorblackColor] forState:(UIControlStateNormal)]; _button.backgroundColor = [UIColoryellowColor]; [self.viewaddSubview:self.button]; //添加点击事件 [_buttonaddTarget:self action:@selector(clickToPicture)forControlEvents:(UIControlEventTouchUpInside)];}//实现点击事件-(void)clickToPicture{ UIImagePickerController *imagePickerController = [[UIImagePickerControlleralloc] init]; imagePickerController.delegate =self; imagePickerController.allowsEditing =YES; //点击后推出 相册控制器 [self presentViewController:imagePickerController animated:YEScompletion:nil]; NSLog(@"进入相册");}//实现 UIImagePickerController代理方法-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ //info 字典中 每个 key所对应的 图片存在 image 对象中,(OriginalImage原始的图片) UIImage *image = [infoobjectForKey:UIImagePickerControllerOriginalImage]; //自定义 imageView让选中的 image 显示在这个view上 UIImageView *imageView = [[UIImageViewalloc] initWithImage:image]; //imageView 尺寸 imageView.frame =CGRectMake(0,100, self.view.frame.size.width,self.view.frame.size.height - 100); //picker 图片后隐藏 UIImagePickerController 视图 [picker dismissViewControllerAnimated:YEScompletion:nil]; //最后把 imageView加载到当前 view [self.view addSubview:imageView]; }//进入相册后 Cancel 键的触发方法-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ //dismiss 后直接回到前一视图 [self dismissViewControllerAnimated:YES completion:nil]; NSLog(@"cancel to picker"); }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
0 0
- iOS9 相册的进入及显示图片
- 进入菜单相册,有的图片的缩略图显示是白色,显示不出来
- iOS9图片保存到相册
- 进入相册选择图片的方法
- picasa相册无法显示图片的解决办法
- 点击进入相册 选择照片并 获取返回值 显示图片
- IOS 调取系统相册 ios9 图片模糊问题
- 打开相册并显示图片
- 手机里的图片在相册里显示不了
- Android 保存图片到相册无法显示的问题
- 关于博客中的126相册图片不显示的问题
- Android 保存图片到相册无法显示的问题
- 获取本地所有图片显示并可多选的本地相册
- Android 保存图片到相册无法显示的问题
- 项目中下载的图片本地系统相册无法显示
- android将下载的图片显示到媒体相册中
- android 4.4以上从相册进入之后,获取图片的路径的方法
- ios9系统图片显示不出来
- 曹欢欢:产品的数据思维PPT
- oracle 查询杀死死锁方案
- 网站
- web前端-工作中经常会用到的一些样式
- 第十一周项目(1):验证算法——层次遍历算法的验证
- iOS9 相册的进入及显示图片
- 第十一周项目一——验证算法(1)层次遍历算法的验证
- 第8周项目3-顺序串算法
- 【学习OpenCV】仿射变换函数warpAffine、旋转
- epoll和select区别
- 怎样保护“/tmp/mysql.sock ”不被删除
- 第十一周--【项目1 - 二叉树算法验证】
- 反射事例代码
- 第十一周 项目一-验证算法