Giter Site home page Giter Site logo

hmimagepicker-1's Introduction

HMImagePicker

Build Status Cocoapods Compatible Platform

轻量级图像选择框架

功能

  • 仿微信照片选择功能,支持横竖屏
  • UIImagePickerController 几乎完全一致的接口调用方式,上手容易
  • 使用 Photos 框架异步加载图片,内存消耗低

屏幕截图

系统支持

  • iOS 8.0+
  • Xcode 7.0

安装

CocoaPods

  • 进入终端,cd 到项目目录,输入以下命令,建立 Podfile
$ pod init
  • 在 Podfile 中输入以下内容:
platform :ios, '8.0'
use_frameworks!

target 'ProjectName' do
pod 'HMImagePicker'
end
  • 在终端中输入以下命令,安装或升级 Pod
# 安装 Pod,第一次使用
$ pod install

# 升级 Pod,后续使用
$ pod update

使用

Objective-C

  • 导入框架
@import HMImagePicker;
  • 在私有扩展中定义属性
@interface MainViewController () <HMImagePickerControllerDelegate>
/// 选中照片数组
@property (nonatomic) NSArray *images;
/// 选中资源素材数组,用于定位已经选择的照片
@property (nonatomic) NSArray *selectedAssets;
@end
  • 在选择按钮的方法中,实现以下代码
- (IBAction)clickSelectPhotoButton {
    HMImagePickerController *picker = [[HMImagePickerController alloc] initWithSelectedAssets:self.selectedAssets];

    // 设置图像选择代理
    picker.pickerDelegate = self;
    // 设置目标图片尺寸
    picker.targetSize = CGSizeMake(600, 600);
    // 设置最大选择照片数量
    picker.maxPickerCount = 9;

    [self presentViewController:picker animated:YES completion:nil];
}
  • 遵守协议
@interface MainViewController () <HMImagePickerControllerDelegate>
  • 实现协议方法
#pragma mark - HMImagePickerControllerDelegate
- (void)imagePickerController:(HMImagePickerController *)picker
      didFinishSelectedImages:(NSArray<UIImage *> *)images
               selectedAssets:(NSArray<PHAsset *> *)selectedAssets {

    // 记录图像,方便在 CollectionView 显示
    self.images = images;
    // 记录选中资源集合,方便再次选择照片定位
    self.selectedAssets = selectedAssets;

    [self.collectionView reloadData];

    [self dismissViewControllerAnimated:YES completion:nil];
}

hmimagepicker-1's People

Contributors

liufan321 avatar

Watchers

ruanjh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.