测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2015年9月 |
由 Lucas Eduardo 维护。
想要一个漂亮的图片裁剪编辑器?对苹果提供的裁剪工具不满意?喜欢圆形图片?LECropPictureViewController
就是您要找的组件 :)!请查看下面的 gif 动图,了解其工作原理
将 LECropPictureViewController 文件夹中的所有文件拖放到您的项目中,或者将其添加为 git submodule。
LECropPictureViewController
适用于任何图片。您只需在创建新实例时提供图片和裁剪类型,然后显示视图控制器。可能的裁剪类型有
LECropPictureTypeRounded
LECropPictureTypeRect
#import "LECropPictureViewController.h"
LECropPictureViewController *cropPictureController = [[LECropPictureViewController alloc] initWithImage:image andCropPictureType:LECropPictureTypeRounded];
[self presentViewController:cropPictureController animated:YES completion:nil];
裁剪图片的回调通过块给出。以下是一个例子,展示如何在 UIImagePickerController 的代理中显示 LECropPictureViewController
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:NO completion:nil];
LECropPictureViewController *cropPictureController = [[LECropPictureViewController alloc] initWithImage:image andCropPictureType:LECropPictureTypeRounded];
cropPictureController.imageView.contentMode = UIViewContentModeScaleAspectFit;
cropPictureController.photoAcceptedBlock = ^(UIImage *croppedPicture){
self.imageView.image = croppedPicture;
};
[self presentViewController:cropPictureController animated:NO completion:nil];
}
LECropPictureViewController
对其组件有公共属性。有了这个,您可以执行一些事情,比如改变 imageView 的 contentMode、改变 barButtonItems 的 text 等。
@property (weak, nonatomic) UIBarButtonItem *cancelButtonItem;
@property (weak, nonatomic) UIBarButtonItem *acceptButtonItem;
@property (weak, nonatomic) UIImageView *imageView;
除了子视图,您还可以自定义其他事情,比如裁剪区域的初始框架、borderColor 和 borderWidth,如下所示
(...)
LECropPictureViewController *cropPictureController = [[LECropPictureViewController alloc] initWithImage:image andCropPictureType:LECropPictureTypeRounded];
cropPictureController.cropFrame = CGRectMake(50, 50, 250, 250);
cropPictureController.borderColor = [UIColor grayColor];
cropPictureController.borderWidth = 1.0;
(...)
您甚至可以实现 @property(copy) void(^photoRejectedBlock)();
,如果您想覆盖取消按钮的默认行为(仅关闭控制器)。请注意,如果您这样做,您将负责自己关闭控制器。
cropPictureController.photoRejectedBlock = ^{
NSLog(@"Doing something here!");
[self dismissViewControllerAnimated:YES completion:nil];
};
喜欢这个项目?有没有缺失的东西或者可以改进的地方?请随时贡献 :)
进行 Fork
创建您的分支 git checkout -b name-your-feature
提交它 git commit -m 'the difference'
推送它 git push origin name-your-feature
创建拉取请求
Lucas Eduardo,[email protected]
LECropPictureViewController 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。