ImageCropper 0.1.5.1

ImageCropper 0.1.5.1

Nick Kopilovskii 维护。




ImageCropper 0.1.5.1

  • 作者
  • Nick Kopilovskii

ImageCropper

Swift License Platform

信息

基于 [MVP + Clean Architecture] (https://github.com/FortechRomania/ios-mvp-clean-architecture/)

使用 [Generatus] (https://github.com/Ryasnoy/Generatus) 创建

描述

实现图像裁剪过程的模块

在创建各种项目的过程中,开发者常常需要裁剪图像(无论是社交网络上的用户头像、背景图像等)。

当然,iOS 通过使用 照片 应用程序提供了自己的图像处理工具,但其使用并非总是方便、合理,甚至可能根本不能使用。

此库提供用户交互手势,根据指定的比例裁剪原始图像部分的功能。

接口

ImageCropperCompletion

public typealias ImageCropperCompletion = (UIImage?) -> Void - 完成图像裁剪时调用的闭包

ImageCropperConfiguration

ImageCropperFigureType - 裁剪用的图形类型

  • circle - 圆形

  • square - 正方形(宽高比为1:1的长方形)

  • rect2x1 - 正方形(宽高比为2:1的长方形)

  • rect1x2 - 正方形(宽高比为1:2的长方形)

  • rect4x3 - 正方形(宽高比为4:3的长方形)

  • rect3x4 - 正方形(宽高比为3:4的长方形)

  • rect16x9 - 正方形(宽高比为16:9的长方形)

  • rect9x16 - 正方形(宽高比为9:16的长方形)

  • customRect - 正方形(具有自定义宽高比的长方形)

*(第一个数字是宽度,第二个是高度)

自定义参数

customRatio - 创建具有自定义宽高比的图形时的大小。此属性的值仅在figure = .customRect时才使用。默认值 - CGSize(width: 1, height: 1)

maskFillColor - 裁剪图形(“孔”)周围的填充颜色

borderColor - 裁剪图形(“孔”)边框的颜色

showGrid - 指定是否显示网格

gridColor - 网格线的颜色

doneTitle - 完成裁剪过程按钮的标题文本(默认:完成

cancelTitle - 取消裁剪过程按钮的标题文本(默认:取消

更新

v.0.1.4

增加

  • 切割图形的变量圆角

修复

用法示例

模块初始化

设置配置

var config = ImageCropperConfiguration(with: img, and: figure)
config.maskFillColor = UIColor(displayP3Red: 0.7, green: 0.5, blue: 0.2, alpha: 0.75)
config.borderColor = UIColor.black

config.showGrid = true
config.gridColor = UIColor.white
config.doneTitle = "CROP"
config.cancelTitle = "Back"

初始化视图控制器

let cropper = ImageCropperViewController.initialize(with: config) { croppedImage in
  /*
    Code to perform after finishing cropping process
  */
}

let cropper = ImageCropperViewController.initialize(with: config, completionHandler: { _croppedImage in
  /*
  Code to perform after finishing cropping process
  */
}) {
  /*
  Code to perform after dismissing controller
  */
}

使用导航控制器显示

navigationController.pushViewController(cropper, animated: true)

模态显示

viewController.present(cropper, animated: true, completion: nil)

用户交互

UIPanGestureRecognizer - 在遮罩和网格下拖动图像的手势

UIPinchGestureRecognizer - 缩放图像的手势

UITapGestureRecognizer - 双击以居中并将图像变换到初始帧

支持的屏幕方向

iPhone 竖屏

iPhone 横屏

iPad 竖屏

iPad 横屏

需求

  • iOS 11.0+
  • Xcode 9.0

安装

ImageCropper 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile:

pod 'ImageCropper'

作者

Nick Kopilovskii, [email protected]

许可证

ImageCropper 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。