實(shí)現(xiàn)與效果
- 微調(diào)角度
- 90°角旋轉(zhuǎn)
- 改變寬高比例
- 旋轉(zhuǎn)和微調(diào)過(guò)程中適應(yīng)邊框填充邊界
- 源碼
微調(diào)角度
- (void)beginTrackingWithTouch {
// 開(kāi)始微調(diào)角度
}
- (void)continueTrackingWithTouch:(CGFloat)value changeValue:(CGFloat)changeValue {
// 調(diào)整中
[self.imageCropperView setRotationAngle:changeValue];
}
- (void)endTrackingWithTouch {
// 微調(diào)角度結(jié)束
}
90°角旋轉(zhuǎn)
- (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];
其他可設(shè)置屬性
/** 裁剪框顏色 / Mask layer color */
**@property (nonatomic, strong) UIColor *maskColor;
/** 裁剪框陰影 / Mask frame color */
**@property (nonatomic, strong) UIColor *shadowColor;
/** 網(wǎng)格線顏色 / Gridlines color */
**@property (nonatomic, strong) UIColor *shapeLayerColor;
/** 是否允許雙指自由旋轉(zhuǎn) / 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;
/** 是否為順勢(shì)轉(zhuǎn)旋轉(zhuǎn) / Is it clockwise rotation , default value is NO */
**@property (nonatomic, assign, getter=isClockwiseRotation) BOOL clockwiseRotation;
/** 重置 / reset */
- (void)reset:(BOOL)animated;
/** 設(shè)置【裁剪比例】 / Setup the cut scale */
**@property (nonatomic, assign) CGSize resizeWHRatio;
- (void)setResizeWHRatio:(CGSize)resizeWHRatio;
- (void)setResizeWHRatio:(CGSize)resizeWHRatio animated:(BOOL)animated;
/** 設(shè)置【旋轉(zhuǎn)角度】/ Setup the rotation angle */
@property (nonatomic, assign) CGFloat rotationAngle;
- (void)rotation:(BOOL)animated;
- (void)setRotationAngle:(CGFloat)rotationAngle;
- (void)setRotationAngle:(CGFloat)rotationAngle animated:(BOOL)animated;
關(guān)于旋轉(zhuǎn)和微調(diào)過(guò)程中適應(yīng)邊框填充邊界的計(jì)算方式
旋轉(zhuǎn)過(guò)程中政溃,為防止漏出黑色背景區(qū)域,需要在調(diào)整過(guò)程中對(duì) scrollview 進(jìn)行縮放态秧,以滿(mǎn)足圖片充滿(mǎn)裁剪區(qū)域董虱,計(jì)算方式如下:
即:
scrollview.width = CGRectGetWidth(maskRect) * cos(a) + CGRectGetHeight(maskRect) * sin(a);
scrollview.height = CGRectGetHeight(maskRect) * cos(a) + CGRectGetWidth(maskRect) * sin(a);
源碼
有興趣的可以下載看下申鱼,希望大佬多多點(diǎn)星愤诱。