测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可 | MIT |
发布最后发布 | 2016年3月 |
由 Ignacio Romero,Ignacio 维护。
这是 iOS 的一款照片搜索/选择器,使用流行的服务提供商如 500px、Flickr、Instagram、Google、Bing 和 Getty Images。该控件尽量模仿 UIKit 的 UIImagePickerController 在性能、外观和行为方面的功能。
在 CocoaPods 中可用
pod 'DZNPhotoPickerController'
安装时,将自动安装以下依赖项
有关完整文档,请访问 CocoaPods 自动生成的文档
#import <DZNPhotoPickerController/DZNPhotoPickerController.h>
在创建 DZNPhotoPickerController 的新实例之前,建议您在其 UIViewController 的类方法 +initialize 中注册您所需要的照片服务 API,如下所示
+ (void)initialize
{
[DZNPhotoPickerController registerService:DZNPhotoPickerControllerService500px
consumerKey:YOUR_500px_KEY
consumerSecret:YOUR_500px_SECRET
subscription:DZNPhotoPickerControllerSubscriptionFree];
[DZNPhotoPickerController registerService:DZNPhotoPickerControllerServiceFlickr
consumerKey:YOUR_Flickr_KEY
consumerSecret:YOUR_Flickr_SECRET
subscription:DZNPhotoPickerControllerSubscriptionFree];
}
创建 DZNPhotoPickerController 的新实例与使用 UIImagePickerController 时非常相似
DZNPhotoPickerController *picker = [[DZNPhotoPickerController alloc] init];
picker.supportedServices = DZNPhotoPickerControllerService500px | DZNPhotoPickerControllerServiceFlickr;
picker.allowsEditing = YES;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
您还可以设置更多属性
picker.initialSearchTerm = @"Surf";
picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
picker.enablePhotoDownload = YES;
picker.supportedLicenses = DZNPhotoPickerControllerCCLicenseBY_ALL;
picker.allowAutoCompletedSearch = YES;
您可以选择使用图片选择器的方法而不是使用代理的方法进行块方法操作
picker.finalizationBlock = ^(DZNPhotoPickerController *picker, NSDictionary *info) {
//Your implementation here
};
picker.failureBlock = ^(DZNPhotoPickerController *picker, NSError *error) {
//Your implementation here
};
picker.cancellationBlock = ^(DZNPhotoPickerController *picker) {
//Your implementation here
};
如果未使用DZNPhotoPickerController
,您可以将其作为子规范安装
pod 'DZNPhotoPickerController/Editor'
如果您已经有了要编辑的图片,只需简单地进行以下操作
DZNPhotoEditorViewController *editor = [[DZNPhotoEditorViewController alloc] initWithImage:self.myImage];
editor.cropMode = DZNPhotoEditorViewControllerCropModeCustom;
editor.cropSize = CGSizeMake(CGRectGetWidth(self.view.frame), 200.0);
[editor setAcceptBlock:^(DZNPhotoEditorViewController *editor, NSDictionary *userInfo){
//Your implementation here
}];
[editor setCancelBlock:^(DZNPhotoEditorViewController *editor){
//Your implementation here
}];
// The view controller requieres to be nested in a navigation controller
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:navigation];
[self presentViewController:controller animated:YES completion:nil];
DZNPhotoPickerController的另一个出色功能是:在使用UIImagePickerController时允许圆形编辑模式,就像在编辑用户头像时联系人应用那样。请注意,由于圆形模式的主要目的是对齐裁剪,所以它仍然导出方形图片。如果您想在您的应用中显示圆形图片,您需要自行实现它。
使用方法非常简单
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
[self presentViewController:picker animated:YES completion:nil];
同时,也对UIImagePickerController提供了块支持!它用两个块属性替换了两个传统委托方法
picker.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
//Your implementation here
};
picker.cancellationBlock = ^(UIImagePickerController *picker) {
//Your implementation here
};
请查看示例项目。一切都在那里。
pod依赖项不受版本管理,因此请在运行项目之前确保调用
pod install
请随时与该项目协作!非常感谢
您是否在您的应用中使用了此控件?在[email protected]告诉我。
(MIT许可协议)
版权所有(c)2014 Ignacio Romero Zurbuchen [email protected]
特此允许任何获得此软件及其相关文档副本(该“软件”)的个人以任何形式使用该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许提供软件的个人或实体这样做,前提是以下条件
上述版权声明和本许可声明应包含在软件所有副本或大部分副本中。
本软件按照“现状”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任(无论是基于合同、侵权或其他原因)负责,造成由此软件或其使用或对本软件或其他处理而引起的任何索赔、损害或其他责任。