DIYAssetPicker 是 UIImagePickerController 的替代品。它适用于所有屏幕方向,并打包了方便的缩略图到输出字典中。
DIYAssetPickerController *picker = [[DIYAssetPickerController alloc] init];
picker.delegate = self;
[self presentModalViewController:picker animated:true];
[picker release];
方法:
@protocol DIYAssetPickerControllerDelegate <NSObject>
@required
// These are equivalent to the UIImagePickerController delegate methods
- (void)pickerDidCancel:(DIYAssetPickerController *)picker;
- (void)pickerDidFinishPickingWithInfo:(NSDictionary *)info;
@optional
// The picker takes a few hundred milliseconds to load libraries with hundreds of items; use this if you want to do something cute during loading
- (void)pickerDidFinishLoading;
// Hook this up to shouldAutorotateToInterfaceOrientation in the delegate if you want the picker to autorotate
- (BOOL)shouldPickerAutorotate:(UIInterfaceOrientation)toInterfaceOrientation;
@end
输出字典键:
// Same as Apple's
NSString *const UIImagePickerControllerMediaType;
NSString *const UIImagePickerControllerOriginalImage;
NSString *const UIImagePickerControllerReferenceURL;
NSString *const UIImagePickerControllerMediaURL;
// NEW STUFF
NSString *const DIYAssetPickerThumbnail; // UIImage of the asset's thumbnail
请查看 UIImagePickerControllerDelegate 协议参考
@property (assign) id<DIYAssetPickerControllerDelegate> delegate;
// Set assetType to show only photos, only videos, or both. Defaults to both
@property (nonatomic, assign) DIYAssetPickerControllerAssetType assetType;
DIYAssetPicker 从 v0.3.0 版本开始使用 ARC 构建。如果您将 DIYAssetPicker 包含在一个不使用 Automatic Reference Counting (ARC) 的项目中,您需要在所有 DIYAssetPicker 源文件上设置 -fobjc-arc 编译器标志。要这样做,请打开 Xcode 并进入您的目标,选择 "构建阶段" 选项卡。现在选择所有 DIYAssetPicker 源文件,按 Enter 键,插入 -fobjc-arc,然后选择 "完成" 以启用 DIYAssetPicker 的 ARC。
Brandon Coston 在 PhotoPickerPlus 中做一些智能的事情来创建一个网格表格视图。我从中完全借鉴了一些想法和代码。Andrew Sliwinski 审阅了代码并推动我使它变得更好。