zoukankan      html  css  js  c++  java
  • 通讯录——选择图片

    //
    //  ViewController.m
    //  Photo
    //
    //  Created by lanou on 16/1/27.
    //  Copyright (c) 2016年 lanou. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
    @property (strong, nonatomic) IBOutlet UIButton *photoBtn;
    @property (strong, nonatomic) IBOutlet UIImageView *imageView;
    @end
    
    @implementation ViewController
    - (IBAction)click:(id)sender {
        UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"提醒" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
            //判断设备是否存在摄像头,有,调用系统摄像头,没有,提醒用户
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                //创建相机
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                //指定数据来源来自于相机
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                //指定代理
                picker.delegate = self;
                //允许编辑
                picker.allowsEditing = YES;
                //模态弹出相机
                [self presentViewController:picker animated:YES completion:nil];
                
            }else{//没有摄像头,提醒用户
                UIAlertController *alter1 = [UIAlertController alertControllerWithTitle:@"您的设备没有摄像头" message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                [alter1 addAction:action1];
                //模态弹出 UIAlertController
                [self presentViewController:alter1 animated:YES completion:nil];
            }
        }];
        [alter addAction:action];
        
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            //指定数据来源于相册
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.delegate = self;
            picker.allowsEditing = YES;
            [self presentViewController:picker animated:YES completion:nil];
        }];
        [alter addAction:action2];
        //模态弹出 UIAlertController
        [self presentViewController:alter animated:YES completion:nil];
    }
    //选取图片后执行的方法
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
        NSLog(@"%@", info);
        
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        self.imageView.image = image;
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    @end
  • 相关阅读:
    arm SecurCore 处理器【转】
    ARM内核全解析,从ARM7,ARM9到Cortex-A7,A8,A9,A12,A15到Cortex-A53,A57【转】
    arm处理器中a5 a8 a9,v6 v7,arm7 arm9 arm11都是依据什么来分类的【转】
    platform型设备在/dev目录下自动创建设备节点的分析【转】
    linux下bus、devices和platform的基础模型 【转】
    kernel 中 sscanf和sprintf()函数使用说明【转】
    Linux内核中的printf实现【转】
    sprintf,snprintf的用法(可以作为linux中itoa函数的补充)【转】
    Linux设备模型(3)_Uevent【转】
    Linux内核中的GPIO系统之(3):pin controller driver代码分析--devm_kzalloc使用【转】
  • 原文地址:https://www.cnblogs.com/chongyu/p/5209415.html
Copyright © 2011-2022 走看看