zoukankan      html  css  js  c++  java
  • Interaction with the camera or the photo library

    As we said before, we need a delegate to deal with the user interaction with the camera or the photo library. In order to do that we have to conform to the UIImagePickerControllerDelegate protocol. Also, since we are going to present the camera (or the photo library) modally, we have to implement the UINavigationControllerDelegate protocol as well. Add both protocols to the AppViewController.h file:

    1
    @interface APPViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

    When the user clicks (touch up inside) the “Take Photo” button, we have to create an UIImagePickerController and set its delegate to our AppViewController class. Also, we have to specify which kind of image picker we want to show, the camera with UIImagePickerControllerSourceTypeCamera, or a photo library with UIImagePickerControllerSourceTypePhotoLibrary; in this case we select the Camera. Once the picker has been crated, we have to present it modally with the method presentViewController.

    Write the following takePhoto acton method:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    - (IBAction)takePhoto:(UIButton *)sender {
        
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        [self presentViewController:picker animated:YES completion:NULL];
        
    }

    Finally, we do the same for the selectPhoto action method, but changing the sourceType to UIImagePickerControllerSourceTypePhotoLibrary.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    - (IBAction)selectPhoto:(UIButton *)sender {
        
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        
        [self presentViewController:picker animated:YES completion:NULL];

        
    }
  • 相关阅读:
    vue computed 可以使用getter和setter
    java压缩zip文件中文乱码问题
    python使用zipfile解压中文乱码问题
    python操作Excel的几种方式
    用python解析word文件(段落篇(paragraph) 表格篇(table) 样式篇(style))
    Python 解压缩Zip和Rar文件到指定目录
    table--边框样式设置
    Postman使用详解
    BootStrap一页通(样式+组件+插件)
    远程连接软件TeamViewer
  • 原文地址:https://www.cnblogs.com/vonk/p/4296472.html
Copyright © 2011-2022 走看看