zoukankan      html  css  js  c++  java
  • iOS中调用系统相册以及使用系统相册的照片

    #import "ViewController.h"
    
    @interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
    @property (nonatomic,strong)UIImageView *headImageView;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
        _headImageView.backgroundColor = [UIColor yellowColor];
        _headImageView.layer.cornerRadius = 50;
        _headImageView.layer.masksToBounds = YES;
        _headImageView.tag = 101;
        [self.view addSubview:_headImageView];
        
        _headImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        [_headImageView addGestureRecognizer:tap];
        
        
        
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)tapAction:(UIImageView*)sender
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.delegate = self;
        [self presentViewController:imagePicker animated:YES completion:^{
            NSLog(@"打开相册");
        }];
    }
    
    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
    {
        [picker dismissViewControllerAnimated:YES completion:^{
            NSLog(@"取消");
        }];
    }
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        _headImageView.image = info[UIImagePickerControllerEditedImage];
        NSLog(@"%@",info);
        [picker dismissViewControllerAnimated:YES completion:^{
            NSLog(@"选照片");
        }];
        
        
        
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    如何一次插入多条记录的SQL语句
    oracle 创建联合主键语句
    02-36 支持向量回归
    245 第三篇:Django-路由控制
    244 第二篇:Django简介
    243 第一篇:自定义Web框架
    242 第一篇:Http协议详细介绍
    02-34 非线性支持向量机(鸢尾花分类)+自定义数据分类
    241 第一篇:web应用
    240 vue学习【第6篇】:vue之导入Bootstrap
  • 原文地址:https://www.cnblogs.com/cityingma/p/4883401.html
Copyright © 2011-2022 走看看