UzysAssetsPickerController 0.9.9

UzysAssetsPickerController 0.9.9

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年7月

Uzysjung macAir维护。



  • UzysJung

替代 UIImagePickerController ,您可以拍照并且选择多张照片和视频

Screenshot

截图截图 UzysAssetsPickerController 的功能:

  • 使用 Interface Builder 轻松自定义。(XIB - 'UzysAssetsPickerController.xib')
  • 带有 Assetpicker,您可以拍照或录制视频。
  • UzysAssetPickerController 会自动更新由其他应用程序拍摄并保存的照片
  • 仅支持 ARC(如果您的项目不使用 ARC ,在 File -> Build Phases Tab -> Compile Sources Section 中双击文件名,然后在弹出的窗口中添加 -fno-objc-arc。)

安装

  1. 只需将 pod 'UzysAssetsPickerController' 添加到您的 Podfile。
  2. 将库文件夹复制到项目文件夹

用法

导入头文件。

#import "UzysAssetsPickerController.h"

自定义 UzysAssetsPickerController 的外观

如果您想自定义 UzysAssetsPickerController 的外观,您可以初始化 UzysAppearanceConfig 实例,并配置其属性,然后在初始化 UzysAssetsPickerController 之前调用

    + (void)setUpAppearanceConfig:(UzysAppearanceConfig *)config

的 UzysAssetsPickerController

示例代码如下

    UzysAppearanceConfig *appearanceConfig = [[UzysAppearanceConfig alloc] init];
    appearanceConfig.finishSelectionButtonColor = [UIColor blueColor];
    appearanceConfig.assetsGroupSelectedImageName = @"checker";
    [UzysAssetsPickerController setUpAppearanceConfig:appearanceConfig];

有关更多可配置的属性,请参阅 UzysAppearanceConfig.h

打开 UzysAssetsPickerController

    UzysAssetsPickerController *picker = [[UzysAssetsPickerController alloc] init];
    picker.delegate = self;
    picker.maximumNumberOfSelectionMedia = 2;
    [self presentViewController:picker animated:YES completion:^{

    }];

UzysAssetPickerControllerDelegate

- (void)uzysAssetsPickerController:(UzysAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
    __weak typeof(self) weakSelf = self;
    if([[assets[0] valueForProperty:@"ALAssetPropertyType"] isEqualToString:@"ALAssetTypePhoto"]) //Photo
    {
            [assets enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                ALAsset *representation = obj;

                    UIImage *img = [UIImage imageWithCGImage:representation.defaultRepresentation.fullResolutionImage
                                                       scale:representation.defaultRepresentation.scale
                                                 orientation:(UIImageOrientation)representation.defaultRepresentation.orientation];
                weakSelf.imageView.image = img;
                *stop = YES;
            }];


    }
    else //Video
    {
        ALAsset *alAsset = assets[0];

        UIImage *img = [UIImage imageWithCGImage:alAsset.defaultRepresentation.fullResolutionImage
                                           scale:alAsset.defaultRepresentation.scale
                                     orientation:(UIImageOrientation)alAsset.defaultRepresentation.orientation];
        weakSelf.imageView.image = img;



        ALAssetRepresentation *representation = alAsset.defaultRepresentation;
        NSURL *movieURL = representation.url;
        NSURL *uploadURL = [NSURL fileURLWithPath:[[NSTemporaryDirectory() stringByAppendingPathComponent:@"test"] stringByAppendingString:@".mp4"]];
        AVAsset *asset      = [AVURLAsset URLAssetWithURL:movieURL options:nil];
        AVAssetExportSession *session =
        [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetMediumQuality];

        session.outputFileType  = AVFileTypeQuickTimeMovie;
        session.outputURL       = uploadURL;

        [session exportAsynchronouslyWithCompletionHandler:^{

            if (session.status == AVAssetExportSessionStatusCompleted)
            {
                NSLog(@"output Video URL %@",uploadURL);
            }

        }];

    }
}

筛选选项

仅图片

  UzysAssetsPickerController *picker = [[UzysAssetsPickerController alloc] init];
  picker.delegate = self;
  picker.maximumNumberOfSelectionVideo = 0;
  picker.maximumNumberOfSelectionPhoto = 3;

仅视频

  UzysAssetsPickerController *picker = [[UzysAssetsPickerController alloc] init];
  picker.delegate = self;
  picker.maximumNumberOfSelectionVideo = 3;
  picker.maximumNumberOfSelectionPhoto = 0;

图片或视频

  UzysAssetsPickerController *picker = [[UzysAssetsPickerController alloc] init];
  picker.delegate = self;
  picker.maximumNumberOfSelectionVideo = 4;
  picker.maximumNumberOfSelectionPhoto = 3;

图片和视频

  UzysAssetsPickerController *picker = [[UzysAssetsPickerController alloc] init];
  picker.delegate = self;
  picker.maximumNumberOfSelectionMedia = 5;

自定义

  • 您可以使用 InterfaceBuilder 轻松修改 UzysAssetsPickerController 设计
  • 请查看 'UzysAssetsPickerController.xib'

变更日志

  • V0.9.6 - 由于支持 Swift,更改了 Delegate 方法名称。[https://github.com/uzysjung/UzysAssetsPickerController/pull/28](#28)
  • V0.9.7 - 修复了 self 保留问题。
  • V0.9.8 - 实现选择顺序;设置更改 cellspacing 列数;支持在 SWIFT 上使用 Cocoapod。

联系

许可