GMImagePicker 0.0.2

GMImagePicker 0.0.2

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2016年1月

Guillermo Muntaner 维护。




一个支持多选图片和视频的图片选择器。采用新的iOS 8 Photo框架

屏幕截图

Screenshot

功能

  1. 允许选择多张照片和视频,甚至来自不同的相册。
  2. 可选的底部工具栏,显示用户选择的信息。
  3. 支持横屏方向和屏幕旋转!
  4. 可以作为iPad的Popover使用,自定义大小。
  5. 完全可定制对智能集合并的访问:收藏慢动作最近删除
  6. 动态大小的网格视图,易于自定义,完全兼容iPhone 6/6+和iPad。
  7. 在特性、外观和行为方面模仿UIImagePickerController。
  8. 由PHCachingImageManager提供,速度快且内存占用小。
  9. 完全采用新的iOS8 PhotoKit,返回一个PHAssets数组。

使用方法

安装

手动

下载并将GMImagePicker文件夹导入到您的项目中。

导入头文件

#import "GMImagePickerController.h"

初始化选择器、设置委托并展示它。

    GMImagePickerController *picker = [[GMImagePickerController alloc] init];
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:nil];

委托

在您的类中实现GMImagePickerControllerDelegate协议

@interface YourViewController : UIViewController <GMImagePickerControllerDelegate>

实现didFinishPickingAssets委托方法。请注意,当操作完成时,您负责关闭选择器,并处理返回的(NSArray *)assetArray

- (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickingAssets:(NSArray *)assetArray
{
    [picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"GMImagePicker: User ended picking assets. Number of selected items is: %lu", (unsigned long)assetArray.count);
}

您还可以实现可选的assetsPickerControllerDidCancel

-(void)assetsPickerControllerDidCancel:(GMImagePickerController *)picker
{
    NSLog(@"GMImagePicker: User pressed cancel button");
}

自定义

在展示选择器之前,您可以自定义一些属性

    ...
    //Display or not the selection info Toolbar:
    picker.displaySelectionInfoToolbar = YES;

    //Display or not the number of assets in each album:
    picker.displayAlbumsNumberOfAssets = YES;

    //Customize the picker title and prompt (helper message over the title)
    picker.title = @"Custom title";
    picker.customNavigationBarPrompt = @"Custom helper message!";

    //Customize the number of cols depending on orientation and the inter-item spacing
    picker.colsInPortrait = 3;
    picker.colsInLandscape = 5;
    picker.minimumInteritemSpacing = 2.0;

    //You can pick the smart collections you want to show:
    _customSmartCollections = @[@(PHAssetCollectionSubtypeSmartAlbumFavorites),
                                @(PHAssetCollectionSubtypeSmartAlbumRecentlyAdded),
                                @(PHAssetCollectionSubtypeSmartAlbumVideos),
                                @(PHAssetCollectionSubtypeSmartAlbumSlomoVideos),
                                @(PHAssetCollectionSubtypeSmartAlbumTimelapses),
                                @(PHAssetCollectionSubtypeSmartAlbumBursts),
                                @(PHAssetCollectionSubtypeSmartAlbumPanoramas)];
    ...

作为iPad的Popover使用

也可作为iPad的Popover使用(可自定义大小)

Screenshot

此代码在iPhone和iPad上均适用

    ...
    GMImagePickerController *picker = [[GMImagePickerController alloc] init];
    picker.delegate = self;

    picker.title = @"Custom title";
    picker.customNavigationBarPrompt = @"Custom helper message!";
    picker.colsInPortrait = 3;
    picker.colsInLandscape = 5;
    picker.minimumInteritemSpacing = 2.0;
    picker.modalPresentationStyle = UIModalPresentationPopover;

    UIPopoverPresentationController *popPC = picker.popoverPresentationController;
    popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
    popPC.sourceView = _gmImagePickerButton;
    popPC.sourceRect = _gmImagePickerButton.bounds;

    [self showViewController:picker sender:nil];

最低要求

Xcode 6和iOS 8。

许可

MIT许可(MIT)

版权(c)2014 Guillermo Muntaner

hereby granted, any person obtaining a copy of this software and associated documentation files (the "Software") to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions

copy or substantial portions of the Software.

provided "as is", kinds of warranty, express or implied, including but not limited to the warranties of merchantability, suitability for a particular purpose and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damage or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other regulation of the software.