objective-c UIImagePickerController 相册视图控制器
2016-01-05 00:00
555 查看
//
// ViewController.m
// 相册
//
// Created by DC017 on 16/1/5.
// Copyright © 2016年 DC017. All rights reserved.
//
#import "ViewController.h"
//要遵守两个协议UINavigationControllerDelegate,UIImagePickerControllerDelegate
@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
{
UIImagePickerController * imagePickerControll;//系统照片选择控制器
UIImageView * imageView;//用来显示选择的图片
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self layout];
}
- (IBAction)open:(id)sender {
//模态跳转(一般用于视图控制器---Controller)
[self presentViewController:imagePickerControll animated:YES completion:nil];
}
-(void)layout{
//初始化选择器
imagePickerControll=[[UIImagePickerController alloc]init];
imagePickerControll.delegate=self;
imageView=[[UIImageView alloc]initWithFrame:CGRectMake(40, 100, 200, 200)];
imageView.contentMode=UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView];
}
//协议里的方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
//从哪里来到哪里去(跳转)
[self dismissViewControllerAnimated:YES completion:nil];
//将相册里的照片显示在界面上
UIImage * image=[info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image=image;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
// ViewController.m
// 相册
//
// Created by DC017 on 16/1/5.
// Copyright © 2016年 DC017. All rights reserved.
//
#import "ViewController.h"
//要遵守两个协议UINavigationControllerDelegate,UIImagePickerControllerDelegate
@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
{
UIImagePickerController * imagePickerControll;//系统照片选择控制器
UIImageView * imageView;//用来显示选择的图片
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self layout];
}
- (IBAction)open:(id)sender {
//模态跳转(一般用于视图控制器---Controller)
[self presentViewController:imagePickerControll animated:YES completion:nil];
}
-(void)layout{
//初始化选择器
imagePickerControll=[[UIImagePickerController alloc]init];
imagePickerControll.delegate=self;
imageView=[[UIImageView alloc]initWithFrame:CGRectMake(40, 100, 200, 200)];
imageView.contentMode=UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView];
}
//协议里的方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
//从哪里来到哪里去(跳转)
[self dismissViewControllerAnimated:YES completion:nil];
//将相册里的照片显示在界面上
UIImage * image=[info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image=image;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- 【已解决】iPhone/iOS中保存自定义对象(Custom Object/Custom Class)的数组(NSMutableArray/NSArray)到NSUserDefaults
- IOS开发系列--Objective-C之KVC、KVO
- Objective-c:isKindOfClass 与 isMemberOfClass
- [Objective-C] id类型和instancetype类型
- Objective-c:类簇
- IOS开发基础Object-C( 14)-- 字符串的使用方法
- 【Objective-C学习记录】第三十四天
- Debugging Objects
- objective-c中实现函数重载(黑魔法:__attribute__((overloadable)))
- Object-c __attribute__((overloadable))) 用法
- 预定义的类型System.Object未定义或未导入
- JSONObject使用方法
- Uinty ScriptableObject的用法
- 如何使用GameObject类发送消息
- iOS UIView动画详解(Objective-C)
- DELPHI调用JAVA WEBSERVICE方法 出现 null object 异常的原因
- Objective-C学习篇第十二弹:键值观察KVO详解
- 使用Objective-C获取每日必应壁纸设置为桌面
- Objective-C类方法中使用self注意事项
- Objective-C中@property的所有属性详解