是 iOS-PEPhotoCropEditor 的另一个分支,修复了 Swift 中的错误。
iOS 的图像裁剪库,类似于 Photos.app 的 UI。
特性
或直接使用裁剪视图
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];
CocoaPods 是以下项目之一: