
cover.jpg
簡介
高仿小紅書App裁剪功能的工具:
1.集成類似小紅書基本的裁剪功能;
2.API簡單易用;
3.切換裁剪比例時可設置帶有動畫過渡,不會那么生硬;
4.可異步可同步裁剪,并且可壓縮。

example.gif
How to use
很簡單:
初始化
// 1.Import
import JPCrop
// 2.Initialize
let croper = Croper(frame: croperFrame, configure)
// 3.Add to superview, done!
view.insertSubview(croper, at: 0)
旋轉
// 默認范圍 -45° ~ 45°
croper.updateRadian(radian)
// 旋轉時展示更多網(wǎng)格
// animated: with animation or not
croper.showRotateGrid(animated: true)
// 旋轉完隱藏更多網(wǎng)格
// animated: with animation or not
croper.hideRotateGrid(animated: true)
切換裁剪寬高比
// 可更新旋轉時的網(wǎng)格數(shù): Number of grid in rotation
// animated: 是否帶動畫效果
croper.updateCropWHRatio(3.0 / 4.0, rotateGridCount: (6, 5), animated: true)
恢復
// 恢復至0°、縮放比例為1、中心點位置的狀態(tài)
// animated: 是否帶動畫效果
croper.recover(animated: true)
裁剪
let configure = croper.syncConfigure()
// 1.同步裁剪
let image = croper.crop()
cropDone?(image, configure)
// 2.異步裁剪: 會在 DispatchQueue.global 里面進行裁剪, 裁剪結束后返回至 DispatchQueue.main 回調裁剪后的圖片
croper.asyncCrop {
guard let image = $0 else { return }
cropDone(image, configure)
}
// PS: 可以設置 compressionScale 屬性進行圖片壓縮(按比例)
更多特性將陸續(xù)加入...
安裝
JPCrop is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'JPCrop'
如有Bug請聯(lián)系我,感謝~
Rogue24, zhoujianping24@hotmail.com