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
  • 相关阅读:
    [bzoj4131]并行博弈_博弈论
    [bzoj1874][BeiJing2009 WinterCamp]取石子游戏_博弈论
    [bzoj4281][ONTAK2015]Związek Harcerstwa Bajtockiego_倍增LCA
    [bzoj2091][Poi2010]The Minima Game_动态规划
    [bzoj1578][Usaco2009 Feb]Stock Market 股票市场_完全背包dp
    常用正则表达式
    webSQL的基本操作
    《css3揭秘》的效果code
    笛卡尔积算法的sku
    仿制淘宝sku点击效果
  • 原文地址:https://www.cnblogs.com/chongyu/p/5209415.html
Copyright © 2011-2022 走看看