ViewController.m
#import "ViewController.h"
@interface ViewController ()<UINavigationControllerDelegate ,UIImagePickerControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UIImagePickerController *vc = [UIImagePickerController new];
//有三种 照相机 文件夹 相册
// vc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
vc.delegate = self;
vc.allowsEditing = YES;
[self presentViewController:vc animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info{
NSLog(@"%@",info);
UIImage *image = info[@"UIImagePickerControllerOriginalImage"];
UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
iv.image = image;
[self.view addSubview:iv];
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
网友评论