您的位置:首页 > 移动开发 > Objective-C

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: