【iOS】JPCrop 高仿小红书App裁剪功能的工具

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)

// 旋转时展示更多网格
// animated: with animation or not
croper.showRotateGrid(animated: true)

// 旋转完隐藏更多网格
// animated: with animation or not
croper.hideRotateGrid(animated: true)

切换裁剪宽高比

// 可更新旋转时的网格数: Number of grid in rotation
// animated: 是否带动画效果
croper.updateCropWHRatio(3.0 / 4.0, rotateGridCount: (6, 5), animated: true)

恢复

// 恢复至0°、缩放比例为1、中心点位置的状态
// 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 属性进行图片压缩(按比例)

更多特性将陆续加入...

安装

JPCrop is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'JPCrop'

如有Bug请联系我,感谢~

Rogue24, zhoujianping24@hotmail.com

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容