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

实现与效果

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

微调角度

iOS 图片裁剪,旋转角度,微调角度 LEGOImageCropper_第1张图片


- (void)beginTrackingWithTouch {

    // 开始微调角度

}

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

    // 调整中

    [self.imageCropperView setRotationAngle:changeValue];

}

- (void)endTrackingWithTouch {

    // 微调角度结束

}

90°角旋转

iOS 图片裁剪,旋转角度,微调角度 LEGOImageCropper_第2张图片


- (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 进行缩放,以满足图片充满裁剪区域,计算方式如下:

iOS 图片裁剪,旋转角度,微调角度 LEGOImageCropper_第3张图片

即:
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

你可能感兴趣的:(ios,objective-c)