JPCrop
示例
一个具有小红书应用剪裁功能高度仿真的工具类。 Juejin Blog
高仿小红书App裁剪功能的工具:
1.集成类似小红书基本的裁剪功能(自定义裁剪比例 + 360°任意旋转);
2.API简单易用;
3.切换裁剪比例带有动画过渡,不会那么生硬;
4.可异步可同步裁剪,并且可压缩。
如何使用
非常简单
初始化
// 1.Import
import JPCrop
// 2.Initialize
let frame = CGRect(...
let configure = Croper.Configure(image)
let croper = Croper(frame: frame, configure)
// 3.Add to superview, done!
view.insertSubview(croper, at: 0)
旋转
/**
* originAngle: Rotation origin angle.
* There are four origins: 0°/360°, 90°, 180°, 270°
* The rotatable angle range of each origin angle is: -45° ~ 45°
*/
// Rotate (Rotatable angle range: Based on the current origin angle -45° ~ 45°)
croper.rotate(angle)
// Rotate left (originAngle - 90°)
// animated: with animation or not
croper.rotateLeft(animated: true)
// Rotate right (originAngle + 90°)
// animated: with animation or not
croper.rotateRight(animated: true)
// Show grid before rotating
// animated: with animation or not
croper.showRotateGrid(animated: true)
// Hide grid after rotating
// animated: with animation or not
croper.hideRotateGrid(animated: true)
取消裁剪宽度与高度比
// rotateGridCount: Number of grid in rotation. (ver, hor)
// animated: with animation or not
croper.updateCropWHRatio(3.0 / 4.0, rotateGridCount: (6, 5), animated: true)
重置
// animated: with animation or not
croper.recover(animated: true)
裁剪
let configure = croper.syncConfigure()
// 1.Sync crop
let image = croper.crop()
cropDone(image, configure)
// 2.Async crop: crop in DispatchQueue.global, result back to DispatchQueue.main
croper.asyncCrop {
guard let image = $0 else { return }
cropDone(image, configure)
}
// PS: You can set the compressionScale to compress the image
未来将添加更多功能...
安装
JPCrop 可通过 CocoaPods 获取。要安装,只需将以下行添加到 Podfile 中
pod 'JPCrop'
作者
Rogue24, [email protected]
许可证
JPCrop 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。