zoukankan      html  css  js  c++  java
  • iOS 6编程使用Photo Library(照片库)和相机

    将照片库和App集成,可直接访问存储在iPhone、iPad 中的任何图像或拍摄新照片,并在App 中使用。

    1. 为了使用 UIImagePickerController,需要将类声明为遵守2个协议:UIImagePickerControllerDelegate和UINavigationControllerDelegate。

    @interface NoteViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

    2. 显示图像选择器

    下面是点击设置按钮后,需要调用的方法 – 显示图像选择器,让用户选择图像。
    - (IBAction)settingButton:(id)sender {
    UIImagePickerController *imagePicker;
    imagePicker = [[UIImagePickerController alloc] init];

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    imagePicker.delegate = self;
    [self presentViewController:imagePicker animated:YES completion:nil];
    // [self presentModalViewController:imagePicker animated:YES];
    }

    上述注释的代码,在iOS 6  中不赞成使用。

    3. 显示选定的图像

    在用户选择好图像之后,为了对用户选择的图像做出响应,还需要实现委托方法imagePickerController:didFinishPickingMediaWithInfo:,下面是具体的代码:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    //[self dismissModalViewControllerAnimated:YES];
    self.backgroundImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    }

    实现在当前场景的UIImageView元素中显示用户选择的图像。上述注释的代码,在iOS 6  中不赞成使用。





  • 相关阅读:
    浅谈PHP7新特性
    TP5与TP3.X对比
    深入源码理解Spark RDD的数据分区原理
    OpenGL的一些基础概念
    关于Spark RDD 的认识
    Ubuntu安装Cloudera Manager以及CDH5.15.2
    小甲鱼零基础汇编语言学习笔记第六章之包含多个段的程序
    小甲鱼零基础汇编语言学习笔记第五章之[BX]和loop指令
    机器学习入门之决策树算法
    机器学习的基本概念
  • 原文地址:https://www.cnblogs.com/tuncaysanli/p/2727946.html
Copyright © 2011-2022 走看看