iOS 图片裁剪,旋转角度,微调角度 LEGOImageCropper

实现与效果

  • 微调角度
  • 90°角旋转
  • 改变宽高比例
  • 旋转和微调过程中适应边框填充边界
  • 源码

微调角度

微调角度操作


- (void)beginTrackingWithTouch {

    // 开始微调角度

}

- (void)continueTrackingWithTouch:(CGFloat)value changeValue:(CGFloat)changeValue {

    // 调整中

    [self.imageCropperView setRotationAngle:changeValue];

}

- (void)endTrackingWithTouch {

    // 微调角度结束

}

90°角旋转

90°角旋转操作


- (void)rotate:(id)sender {

    [self.imageCropperView rotation:YES];

}

改变宽高比例

改变宽高比例操作


- (void)resizeWHScale:(id)sender {

[UIView animateWithDuration:0.15 animations:^{

 self.imageCropperView.frame = [self imageCropViewFrame:self.currType];

[self.imageCropperView setResizeWHRatio:self.currScale animated:NO];

}completion:nil];

其他可设置属性


/** 裁剪框颜色 / Mask layer color */

**@property (nonatomic, strong) UIColor *maskColor;

/** 裁剪框阴影 / Mask frame color */

**@property (nonatomic, strong) UIColor *shadowColor;

/** 网格线颜色 / Gridlines color */

**@property (nonatomic, strong) UIColor *shapeLayerColor;

/** 是否允许双指自由旋转  / Allow two fingers to rotate freely ,default value is YES */

**@property (nonatomic, assign, getter=isRotationEnabled) BOOL rotationEnabled;

/** 是否允许双击重置 / Allow double click Reset , default value is YES */

**@property (nonatomic, assign, getter=isDoubleResetEnabled) BOOL doubleResetEnabled;

/** 是否为顺势转旋转 / Is it clockwise rotation , default value is NO */

**@property (nonatomic, assign, getter=isClockwiseRotation) BOOL clockwiseRotation;

/** 重置 / reset */

- (void)reset:(BOOL)animated;

/** 设置【裁剪比例】 / Setup the cut scale */

**@property (nonatomic, assign) CGSize resizeWHRatio;

- (void)setResizeWHRatio:(CGSize)resizeWHRatio;

- (void)setResizeWHRatio:(CGSize)resizeWHRatio animated:(BOOL)animated;

/** 设置【旋转角度】/ Setup the rotation angle */

@property (nonatomic, assign) CGFloat rotationAngle;

- (void)rotation:(BOOL)animated;

- (void)setRotationAngle:(CGFloat)rotationAngle;

- (void)setRotationAngle:(CGFloat)rotationAngle animated:(BOOL)animated;

关于旋转和微调过程中适应边框填充边界的计算方式

旋转过程中,为防止漏出黑色背景区域,需要在调整过程中对 scrollview 进行缩放,以满足图片充满裁剪区域,计算方式如下:

地铁上写的计算方法,粗糙

即:
scrollview.width = CGRectGetWidth(maskRect) * cos(a) + CGRectGetHeight(maskRect) * sin(a);
scrollview.height = CGRectGetHeight(maskRect) * cos(a) + CGRectGetWidth(maskRect) * sin(a);

源码

有兴趣的可以下载看下,希望大佬多多点星。

https://github.com/legokit/LEGOImageCropper

GitHub - legokit/LEGOImageCropper: imageCropper, crop image, Picture cropper, support to resizeWHScale, set size, rotate angle, fine adjust angle, image crop. 图片裁剪,支持大小缩放,设置大小,旋转角度,微调角度,裁剪产品图片。。

https://www.jianshu.com/p/16fb4ddf0890

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值