CMPhotoCropEditor 1.0.1

CMPhotoCropEditor 1.0.1

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

Jerry Bao维护。



  • 作者:
  • Jerry

是 iOS-PEPhotoCropEditor 的另一个分支,修复了 Swift 中的错误。

iOS 的图像裁剪库,类似于 Photos.app 的 UI。

特性

适用于 iPhone/iPad

  • 在任何设备方向上都能良好工作
  • 支持缩放手势进行缩放
  • 支持旋转手势
  • 系统要求

iOS 5.0 或更高版本

  • 安装

用法

使用视图控制器组件

或直接使用裁剪视图

 PECropViewController *controller = [[PECropViewController alloc] init];
 controller.delegate = self;
 controller.image = self.imageView.image;

 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
 [self presentViewController:navigationController animated:YES completion:NULL];

获取裁剪图像

self.cropView = [[PECropView alloc] initWithFrame:contentView.bounds];
[self.view addSubview:self.cropView];

委托方法

从视图中直接检索

- (void)cropViewController:(PECropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage
{
    [controller dismissViewControllerAnimated:YES completion:NULL];
    self.imageView.image = croppedImage;
}

调整大小时保持裁剪纵横比

UIImage *croppedImage = self.cropView.croppedImage;

根据图像大小指定裁剪矩形

controller.keepingCropAspectRatio = YES;
self.cropView.keepingCropAspectRatio = YES;

将裁剪矩形重置回原始图像大小和旋转

// e.g.) Cropping center square
CGFloat width = image.size.width;
CGFloat height = image.size.height;
CGFloat length = MIN(width, height);
controller.imageCropRect = CGRectMake((width - length) / 2,
                                      (height - length) / 2,
                                      length,
                                      length);
// e.g.) Cropping center square
CGFloat width = image.size.width;
CGFloat height = image.size.height;
CGFloat length = MIN(width, height);
self.cropView.imageCropRect = CGRectMake((width - length) / 2,
                                         (height - length) / 2,
                                         length,
                                         length);

许可证

[controller resetCropRect];
[self.cropView resetCropRect];

PEPhotoCropEditor 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。

CocoaPods 是以下项目之一: