cover.jpg
簡(jiǎn)介
高仿小紅書App裁剪功能的工具:
1.集成類似小紅書基本的裁剪功能澄阳;
2.API簡(jiǎn)單易用;
3.切換裁剪比例時(shí)可設(shè)置帶有動(dòng)畫過(guò)渡勤讽,不會(huì)那么生硬铲敛;
4.可異步可同步裁剪,并且可壓縮籽孙。
example.gif
How to use
很簡(jiǎn)單:
初始化
// 1.Import
import JPCrop
// 2.Initialize
let croper = Croper(frame: croperFrame, configure)
// 3.Add to superview, done!
view.insertSubview(croper, at: 0)
旋轉(zhuǎn)
// 默認(rèn)范圍 -45° ~ 45°
croper.updateRadian(radian)
// 旋轉(zhuǎn)時(shí)展示更多網(wǎng)格
// animated: with animation or not
croper.showRotateGrid(animated: true)
// 旋轉(zhuǎn)完隱藏更多網(wǎng)格
// animated: with animation or not
croper.hideRotateGrid(animated: true)
切換裁剪寬高比
// 可更新旋轉(zhuǎn)時(shí)的網(wǎng)格數(shù): Number of grid in rotation
// animated: 是否帶動(dòng)畫效果
croper.updateCropWHRatio(3.0 / 4.0, rotateGridCount: (6, 5), animated: true)
恢復(fù)
// 恢復(fù)至0°烈评、縮放比例為1、中心點(diǎn)位置的狀態(tài)
// animated: 是否帶動(dòng)畫效果
croper.recover(animated: true)
裁剪
let configure = croper.syncConfigure()
// 1.同步裁剪
let image = croper.crop()
cropDone?(image, configure)
// 2.異步裁剪: 會(huì)在 DispatchQueue.global 里面進(jìn)行裁剪, 裁剪結(jié)束后返回至 DispatchQueue.main 回調(diào)裁剪后的圖片
croper.asyncCrop {
guard let image = $0 else { return }
cropDone(image, configure)
}
// PS: 可以設(shè)置 compressionScale 屬性進(jìn)行圖片壓縮(按比例)
更多特性將陸續(xù)加入...
安裝
JPCrop is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'JPCrop'
如有Bug請(qǐng)聯(lián)系我犯建,感謝~
Rogue24, zhoujianping24@hotmail.com