//spa
// ViewController.m.net
// 相冊3d
//orm
// Created by DC017 on 16/1/5.圖片
// Copyright © 2016年 DC017. All rights reserved.get
//it
#import "ViewController.h"io
//要遵照兩個協議UINavigationControllerDelegate,UIImagePickerControllerDelegateclass
@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>import
{
UIImagePickerController * imagePickerControll;//系統照片選擇控制器
UIImageView * imageView;//用來顯示選擇的圖片
}
@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.
}