SLPhotoSelection 1.0.0

SLPhotoSelection 1.0.0

Agustin De Leon 维护。



  • 作者
  • agustinslions

SLPhotoSelection

通用

本项目可实现使用相机或手机中已保存的图片轻松实现图片选择功能。

安装

  • 手动

您需要将以下文件添加到您的项目中

  • 包含所有文件的 SLImagePickerController 文件夹。
  • UIViewController+SLPhotoSelection.h
  • UIViewController+SLPhotoSelection.m

对于 iOS 10 及以上版本,您需要在 Info.plist 中定义和提供您的应用访问的所有系统隐私敏感数据的用途说明。

您需要添加以下键值对

<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos.</string>

用途

将文件导入您的类中。

#import "UIViewController+SLPhotoSelection.h"

您有以下四种获取图片和视频的方法。

以下方法允许选择单个图片

    [self addPhotoWithCompletionHandler:^(BOOL success, id object) {
      if (success) {
        //This method return a UIImage in object attribute.
      } else {
        //When fail or cancel 
      }
    }];

以下方法允许选择单个视频

    [self addVideoWithCompletionHandler:^(BOOL success, id object) {
      if (success) {
        //This method return a AVAsset in object attribute.
      } else {
        //When fail or cancel 
      }
    }];

以下方法允许选择多个图片

    [self selectMultiplePhotoWithCompletionHandler:^(BOOL success, NSMutableArray *multiplePhotos) {
      if (success) {
        //This method return a NSMutableArray of PHAssets.
      } else {
        //When fail or cancel 
      }
    }];

以下方法允许选择多个视频

    [self selectMultipleVideoWithCompletionHandler:^(BOOL success, NSMutableArray *multipleVideo) {
      if (success) {
        //This method return a NSMutableArray of PHAssets.
      } else {
        //When fail or cancel 
      }
    }];

我还添加了一个 SLPhotoManage 文件。该类包含两个方法,用于从 PHAssets 获取 UIImage 和从 PHAssets 获取 AVPlayerItem(用于视频)。

  [SLPhotoManager loadImage:asset targetSize:targetSize completion:^(UIImage *image, NSDictionary *info) {
  
  }];
  [SLPhotoManager loadVideo:asset targetSize:targetSize completion:^(AVPlayerItem *playerItem, NSDictionary *info) {

  }];

作者

Agustín De León

Agustín De León

许可

本作品受MIT许可协议的许可 - 详细内容请参阅LICENSE.md文件