[圖片上傳失敗...(image-22fc52-1652684357602)]
設(shè)計圖
[圖片上傳失敗...(image-ac2d02-1652684357602)]
需求說明
需要實現(xiàn)一個檔位切換的功能,點擊上圖中的指示器的位置,自動切換到該指示器所指的位置,并切換當(dāng)前的指示數(shù)字,滑動的交互和點擊的交互一樣。
需求分析以及代碼實現(xiàn)
1.繪制最外圈的圓環(huán)
上圖中,外圈整體的形狀是一個圓環(huán),將圓環(huán)分為三部分,第一檔位區(qū)間,第二檔位區(qū)間,第三檔位區(qū)間。按照貝塞爾曲線繪制圓形的思路,順時針繪制圓形,角度是從pi到2*pi,可以將整個上半圓分為180等份,根據(jù)中間的間距,確定第一區(qū)間的范圍是0-56,第二區(qū)間的范圍是63-117,第三區(qū)間的范圍是124-180,確定范圍后,便可繪制出外圈圓環(huán),具體代碼如下:
//中間圓的圓心
@property (nonatomic, assign) CGPoint circleCenter;
//外圓環(huán)的半徑
@property (nonatomic, assign) CGFloat outerCircleAadius;
/** 底層顯示層 */
@property (nonatomic, strong) CAShapeLayer *lowBottomLayer;
/** 頂層顯示層 */
@property (nonatomic, strong) CAShapeLayer *lowTopLayer;
//第一條線段的進(jìn)度
@property (nonatomic, assign) CGFloat lowProgress;
//第二條線段相關(guān)
@property (nonatomic, strong) CAShapeLayer *middleBottomLayer;
/** 頂層顯示層 */
@property (nonatomic, strong) CAShapeLayer *middleTopLayer;
//第二條線段的進(jìn)度
@property (nonatomic, assign) CGFloat middleProgress;
//第三條線相關(guān)
@property (nonatomic, strong) CAShapeLayer *highBottomLayer;
/** 頂層顯示層 */
@property (nonatomic, strong) CAShapeLayer *highTopLayer;
//第三條線段的進(jìn)度
@property (nonatomic, assign) CGFloat highProgress;
- (CAShapeLayer *)lowBottomLayer
{
if (!_lowBottomLayer) {
_lowBottomLayer = [CAShapeLayer layer];
_lowBottomLayer.lineCap = kCALineCapRound;
_lowBottomLayer.fillColor = [UIColor clearColor].CGColor;
_lowBottomLayer.strokeColor = [kMainColor colorWithAlphaComponent:0.4].CGColor;
_lowBottomLayer.lineWidth = Width_Real(9);
}
return _lowBottomLayer;
}
- (CAShapeLayer *)lowTopLayer
{
if (!_lowTopLayer) {
_lowTopLayer = [CAShapeLayer layer];
_lowTopLayer.lineCap = kCALineCapRound;
_lowTopLayer.fillColor = [UIColor clearColor].CGColor;
_lowTopLayer.strokeColor = kMainColor.CGColor;
_lowTopLayer.lineWidth = Width_Real(9);
}
return _lowTopLayer;
}
- (CAShapeLayer *)middleBottomLayer
{
if (!_middleBottomLayer) {
_middleBottomLayer = [CAShapeLayer layer];
_middleBottomLayer.lineCap = kCALineCapRound;
_middleBottomLayer.fillColor = [UIColor clearColor].CGColor;
_middleBottomLayer.strokeColor = [HEXCOLOR(0xFFE86A) colorWithAlphaComponent:0.4].CGColor;
_middleBottomLayer.lineWidth = Width_Real(9);
}
return _middleBottomLayer;
}
- (CAShapeLayer *)middleTopLayer
{
if (!_middleTopLayer) {
_middleTopLayer = [CAShapeLayer layer];
_middleTopLayer.lineCap = kCALineCapRound;
_middleTopLayer.fillColor = [UIColor clearColor].CGColor;
_middleTopLayer.strokeColor = HEXCOLOR(0xFFE86A).CGColor;
_middleTopLayer.lineWidth = Width_Real(9);
}
return _middleTopLayer;
}
- (CAShapeLayer *)highBottomLayer
{
if (!_highBottomLayer) {
_highBottomLayer = [CAShapeLayer layer];
_highBottomLayer.lineCap = kCALineCapRound;
_highBottomLayer.fillColor = [UIColor clearColor].CGColor;
_highBottomLayer.strokeColor = [HEXCOLOR(0xFF7B4B) colorWithAlphaComponent:0.4].CGColor;
_highBottomLayer.lineWidth = Width_Real(9);
}
return _highBottomLayer;
}
- (CAShapeLayer *)highTopLayer
{
if (!_highTopLayer) {
_highTopLayer = [CAShapeLayer layer];
_highTopLayer.lineCap = kCALineCapRound;
_highTopLayer.fillColor = [UIColor clearColor].CGColor;
_highTopLayer.strokeColor = HEXCOLOR(0xFF7B4B).CGColor;
_highTopLayer.lineWidth = Width_Real(9);
}
return _highTopLayer;
}
//將layer添加到當(dāng)前l(fā)ayer上
[self.layer addSublayer:self.lowBottomLayer];
[self.layer addSublayer:self.lowTopLayer];
UIBezierPath *bottomPath = [UIBezierPath bezierPathWithArcCenter:_circleCenter radius:_outerCircleAadius startAngle:M_PI endAngle:M_PI + AngleToRadian2(56.0) clockwise:YES];
_lowBottomLayer.path = bottomPath.CGPath;
[self.layer addSublayer:self.middleBottomLayer];
[self.layer addSublayer:self.middleTopLayer];
UIBezierPath *bottomPath1 = [UIBezierPath bezierPathWithArcCenter:_circleCenter radius:_outerCircleAadius startAngle:M_PI + AngleToRadian2(63) endAngle:M_PI + AngleToRadian2(117.0) clockwise:YES];
_middleBottomLayer.path = bottomPath1.CGPath;
[self.layer addSublayer:self.highBottomLayer];
[self.layer addSublayer:self.highTopLayer];
UIBezierPath *bottomPath2 = [UIBezierPath bezierPathWithArcCenter:_circleCenter radius:_outerCircleAadius startAngle:M_PI + AngleToRadian2(124) endAngle:M_PI + AngleToRadian2(180.0) clockwise:YES];
_highBottomLayer.path = bottomPath2.CGPath;
2.繪制刻度線
根據(jù)當(dāng)前的刻度的角度,計算出繪刻度矩形的四個點的位置,第一區(qū)間的刻度的角度是30,第二區(qū)間的刻度的角度是90,第三區(qū)間刻度的角度是150,具體的繪制代碼如下:
//繪制中間的分隔線
- (void)addLayer1WithColor:(UIColor *)color withAngleTemp:(CGFloat)angleTemp {
CALayer *layer = [CALayer layer];
layer.backgroundColor = color.CGColor;
layer.frame = CGRectMake(0, 0, self.width, self.height);
[self.layer addSublayer:layer];
CAShapeLayer * maskLayer= [CAShapeLayer layer];
maskLayer.frame = CGRectMake(0, 0, layer.bounds.size.width,layer.bounds.size.height);
NSArray *rectangleFourKeyPointArray = nil;
rectangleFourKeyPointArray = [self calculateFourKeyPointForRectangleWithCircleCenter:CGPointMake((self.width - Width_Real(52) * 2) / 2 + Width_Real(52), self.height - 27) innerCircleRadius:(self.width - Width_Real(52) * 2) / 2 - Width_Real(6) rectangleWidht:Width_Real(2) rectangleHeight:Width_Real(6) angle:angleTemp];
CGPoint topLeftPoint = ((NSValue *)rectangleFourKeyPointArray[0]).CGPointValue;
CGPoint topRightPoint = ((NSValue *)rectangleFourKeyPointArray[1]).CGPointValue;
CGPoint bottomRightPoint = ((NSValue *)rectangleFourKeyPointArray[2]).CGPointValue;
CGPoint bottomLeftPoint = ((NSValue *)rectangleFourKeyPointArray[3]).CGPointValue;
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:topLeftPoint];
[path addLineToPoint:topRightPoint];
[path addLineToPoint:bottomRightPoint];
[path addLineToPoint:bottomLeftPoint];
[path closePath];
maskLayer.path = path.CGPath;
layer.mask = maskLayer;
}
/**
計算矩形的四個頂點坐標(biāo)
@param cirlceCenter 圓心
@param innerCircleRadius 內(nèi)圓半徑
@param rectangleWidht 矩形寬
@param rectangleHeight 矩形高
@param angle 矩形繞圓心的角度
@return 數(shù)組,包含四個頂點坐標(biāo)(順時針,上左,上右,下右,下左)
*/
- (NSArray *)calculateFourKeyPointForRectangleWithCircleCenter:(CGPoint)cirlceCenter innerCircleRadius:(CGFloat)innerCircleRadius rectangleWidht:(CGFloat)rectangleWidht rectangleHeight:(CGFloat)rectangleHeight angle:(CGFloat)angle {
CGFloat cirlceCenterX = cirlceCenter.x;
CGFloat cirlceCenterY = cirlceCenter.y;
CGFloat tempAngle = angle;
CGFloat tempRadian = AngleToRadian2(tempAngle);
CGFloat middlePointX_LeftLine = cirlceCenterX + innerCircleRadius * cos(tempRadian);
CGFloat middlePointY_LeftLine = cirlceCenterY - innerCircleRadius * sin(tempRadian);
CGFloat topLeftPointX = middlePointX_LeftLine - rectangleWidht / 2 * sin(tempRadian);
CGFloat topLeftPointY = middlePointY_LeftLine - rectangleWidht / 2 * cos(tempRadian);
NSValue *topLeftPointValue = [NSValue valueWithCGPoint:CGPointMake(topLeftPointX, topLeftPointY)];
CGFloat topRightPointX = topLeftPointX + rectangleHeight * cos(tempRadian);
CGFloat topRightPointY = topLeftPointY - rectangleHeight * sin(tempRadian);
NSValue *topRightPointValue = [NSValue valueWithCGPoint:CGPointMake(topRightPointX, topRightPointY)];
CGFloat bottomLeftPointX = middlePointX_LeftLine + rectangleWidht / 2 * sin(tempRadian);
CGFloat bottomLeftPointY = middlePointY_LeftLine + rectangleWidht / 2 * cos(tempRadian);
NSValue *bottomLeftPointValue = [NSValue valueWithCGPoint:CGPointMake(bottomLeftPointX, bottomLeftPointY)];
CGFloat bottomRightPointX = bottomLeftPointX + rectangleHeight * cos(tempRadian);
CGFloat bottomRightPointY = bottomLeftPointY - rectangleHeight * sin(tempRadian);
NSValue *bottomRightPointValue = [NSValue valueWithCGPoint:CGPointMake(bottomRightPointX, bottomRightPointY)];
NSArray *pointArray = @[topLeftPointValue, topRightPointValue, bottomRightPointValue, bottomLeftPointValue];
return pointArray;
}
//添加指示線
for (int i = 0; i < 3; i++) {
if (i == 0) {
[self addLayer1WithColor:HEXCOLOR(0xFF7B4B) withAngleTemp:30];
}
else if (i == 1) {
[self addLayer1WithColor:HEXCOLOR(0xFFE86A) withAngleTemp:90];
}
else if (i == 2) {
[self addLayer1WithColor:kMainColor withAngleTemp:150];
}
}
3.繪制指示小圓圈
自定義一個View,對外開放倆個屬性,一個指示標(biāo)的數(shù)字,一個指示標(biāo)的背景顏色,然后讓該View的center和我們計算出來的中心就可以了,具體的代碼如下:
#pragma mark -初始化圓形指示條
- (void)createIndicatorLabel
{
_circleIndictorView = [[SGJCircleIndicatorView alloc] initWithFrame:CGRectMake(0, 0, Width_Real(28), Width_Real(28))];
_circleIndictorView.indicatorLabel.text = [NSString stringWithFormat:@"%ld", [self.currentGearType integerValue]];
[self addSubview:_circleIndictorView];
NSInteger endAngle = 0.0;
endAngle = [self transforAngleByGear:self.currentGearType];
CGFloat redDotCenterY = _circleCenter.y - sin(AngleToRadian2(endAngle)) * _outerCircleAadius;
CGFloat redDotCenterX = Width_Real(40) + (_outerCircleAadius - cos(AngleToRadian2(endAngle)) * _outerCircleAadius);
CGPoint dotCircleCenter = CGPointMake(redDotCenterX, redDotCenterY);
_circleIndictorView.center = dotCircleCenter;
}
#pragma mark -根據(jù)當(dāng)前的檔位返回對應(yīng)的角度
- (CGFloat)transforAngleByGear:(NSString *)gear
{
NSInteger endAngle = 0.0;
if ([gear isEqualToString:@"01"]) {
endAngle = 30;
_circleIndictorView.shadowColor = kMainColor;
if (self.shock) {
AudioServicesPlaySystemSoundWithCompletion(1519, ^{});
}
}
else if ([gear isEqualToString:@"02"])
{
endAngle = 90;
_circleIndictorView.shadowColor = HEXCOLOR(0xFFE86A);
if (self.shock) {
AudioServicesPlaySystemSoundWithCompletion(1519, ^{});
}
}
else if ([gear isEqualToString:@"03"])
{
endAngle = 150;
_circleIndictorView.shadowColor = HEXCOLOR(0xFF7B4B);
if (self.shock) {
AudioServicesPlaySystemSoundWithCompletion(1519, ^{});
}
}
return endAngle;
}
4.添加手勢,實現(xiàn)需要的交互
添加手勢,根據(jù)手勢移動之后獲得的位置點,和圓心點,會計算出來一個角度,根據(jù)該角度的范圍來確定當(dāng)前所屬的區(qū)域,然后實現(xiàn)對應(yīng)的動畫,具體實現(xiàn)如下:
//添加滑動手勢
UILongPressGestureRecognizer *pan = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(touchAction:)];
[self.bgImageView addGestureRecognizer:pan];
pan.minimumPressDuration = 0;
pan.allowableMovement = CGFLOAT_MAX;
// [self setLowerProgress:(AngleToRadian2(10) / AngleToRadian2(56))];
[self setLowerProgress:1.0 isCanSetZero:YES];
[self setMiddlerProgress:0.0 isCanSetZero:YES];
[self setHigherProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
- (void)touchAction:(UILongPressGestureRecognizer *)pan {
CGPoint point = [pan locationInView:self];
if (pan.state == UIGestureRecognizerStateEnded) {
// [HUD hrz_showAutoMsg:[NSString stringWithFormat:@"當(dāng)前的檔位是%@",self.currentGearType]];
if (self.callbackCurrentGearValue) {
self.callbackCurrentGearValue(self.currentGearType);
}
}
if (point.y > _circleCenter.y) {
// [HUD hrz_showAutoMsg:@"滑動區(qū)域超出范圍"];
return;
}
CGFloat angle = angleBetweenPoints1(self.circleCenter, point);
BOOL isCircle = [self panPointIsInCircle:point];
if (isCircle) {
// _currentGearType = @"";
if (angle >= -10 - threshold && angle <= -10 + threshold) {
_currentGearType = @"01";
}
else if (angle >= -30 - threshold && angle <= -30 + threshold)
{
_currentGearType = @"01";
}
else if (angle >= -50 - threshold && angle <= -50 + threshold)
{
_currentGearType = @"01";
}
else if (angle >= -70 - threshold && angle <= -70 + threshold)
{
_currentGearType = @"02";
}
else if (abs(angle) >= 84 && abs(angle) <= 92)
{
_currentGearType = @"02";
}
else if (angle >= 70 - threshold && angle <= 70 + threshold)
{
_currentGearType = @"02";
}
else if (angle >= 50 - threshold && angle <= 50 + threshold)
{
_currentGearType = @"03";
}
else if (angle >= 30 - threshold && angle <= 30 + threshold)
{
_currentGearType = @"03";
}
else if (angle >= 10 - threshold && angle <= 10 + threshold)
{
_currentGearType = @"03";
}
//只有檔位真正發(fā)生改變時,才進(jìn)行賦值操作
if (![_currentGearType isEqualToString:@""]) {
self.shock = YES;
[self animatedWithLastGear:_lastGearType withCurrentGear:_currentGearType];
}
}
else
{
[HUD hrz_showAutoMsg:@"滑動區(qū)域在圓內(nèi)"];
}
}
#pragma mark 點擊事件回調(diào)
- (void)animatedWithLastGear:(NSString *)lastGear withCurrentGear:(NSString *)currentGear
{
//判斷是順時針,還是逆時針
if (lastGear == nil || currentGear == nil) {
return;
}
if (![self judgeGear:lastGear] || ![self judgeGear:currentGear]) {
// [HUD hrz_showAutoMsg:[NSString stringWithFormat:@"當(dāng)前的檔位是%@,即將切換到的檔位是%@",lastGear,currentGear]];
return;
}
if (self.shock) {
if ([currentGear isEqualToString:lastGear]) {
// [HUD hrz_showAutoMsg:@"檔位沒有發(fā)生改變"];
return;
}
}
//判斷是順時針,還是逆時針,默認(rèn)是順時針
if ([currentGear integerValue] > [lastGear integerValue]) {
self.closeWise = YES;
}
else
{
self.closeWise = NO;
}
if (self.shock) {
if (self.valueChangedAction) {
self.valueChangedAction();
}
}
NSInteger currentGearValue = [currentGear integerValue];
NSInteger lastGearValue = [lastGear integerValue];
if ((currentGearValue == 1 && lastGearValue == 3) || (currentGearValue == 3 && lastGearValue == 1)) {
self.changeScope = SGJGearChangeScopeBoth;
}
else if ((currentGearValue == 1 && lastGearValue == 2) || (currentGearValue == 2 && lastGearValue == 1))
{
self.changeScope = SGJGearChangeScopeLowAndMiddle;
}
else if ((currentGearValue == 2 && lastGearValue == 3) || (currentGearValue == 3 && lastGearValue == 2))
{
self.changeScope = SGJGearChangeScopeMiddlAndHigh;
}
NSInteger endAngle = 0.0;
endAngle = [self transforAngleByGear:self.currentGearType];
switch (self.changeScope) {
case SGJGearChangeScopeLow:
{
// NSInteger endAngle = [self.clockwiseArray[currentGearValue - 1] intValue];
// [self setLowerProgress:(AngleToRadian2(endAngle) / AngleToRadian2(56.0))];
[self setLowerProgress:1.0 isCanSetZero:NO];
[self setMiddlerProgress:0.0 isCanSetZero:YES];
[self setHigherProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
break;
case SGJGearChangeScopeMiddle:
{
// NSInteger endAngle = 0.0;
// if ([_currentGearType isEqualToString:@"04"]) {
// endAngle = 10.0;
// }
// else
// {
// endAngle = [self.clockwiseArray[currentGearValue - 1] intValue] - 63;
// }
// [self setMiddlerProgress:(AngleToRadian2(endAngle) / AngleToRadian2(54.0)) isCanSetZero:NO];
[self setMiddlerProgress:1.0 isCanSetZero:NO];
[self setLowerProgress:0.0 isCanSetZero:YES];
[self setHigherProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
break;
case SGJGearChangeScopeHigh:
{
// NSInteger endAngle = [self.clockwiseArray[currentGearValue - 1] intValue] - 124;
[self setHigherProgress:1.0 isCanSetZero:NO];
[self setLowerProgress:0.0 isCanSetZero:YES];
[self setMiddlerProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
break;
case SGJGearChangeScopeBoth:
{
if (self.closeWise) {
//檔位從低到高
// NSInteger endAngle = [self.clockwiseArray[currentGearValue - 1] intValue] - 124;
[self setHigherProgress:1.0 isCanSetZero:NO];
[self setLowerProgress:0.0 isCanSetZero:YES];
[self setMiddlerProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
else
{
//檔位從高到低
// NSInteger endAngle = [self.clockwiseArray[currentGearValue - 1] intValue];
[self setLowerProgress:1.0 isCanSetZero:NO];
[self setMiddlerProgress:0.0 isCanSetZero:YES];
[self setHigherProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
}
break;
case SGJGearChangeScopeLowAndMiddle:
{
if (self.closeWise) {
//檔位從低到高
// NSInteger endAngle = 0.0;
// if ([_currentGearType isEqualToString:@"04"]) {
// endAngle = 10.0;
// }
// else
// {
// endAngle = [self.clockwiseArray[currentGearValue - 1] intValue] - 63;
// }
// [self setMiddlerProgress:(AngleToRadian2(endAngle) / AngleToRadian2(54.0)) isCanSetZero:NO];
[self setMiddlerProgress:1.0 isCanSetZero:NO];
[self setLowerProgress:0.0 isCanSetZero:YES];
[self setHigherProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
else
{
//檔位從高到低
// NSInteger endAngle = [self.clockwiseArray[currentGearValue - 1] intValue];
[self setLowerProgress:1.0 isCanSetZero:NO];
[self setMiddlerProgress:0.0 isCanSetZero:YES];
[self setHigherProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
}
break;
case SGJGearChangeScopeMiddlAndHigh:
{
if (self.closeWise) {
//檔位從低到高
// NSInteger endAngle = [self.clockwiseArray[currentGearValue - 1] intValue] - 124;
// [self setHigherProgress:(AngleToRadian2(endAngle) / AngleToRadian2(56.0)) isCanSetZero:NO];
[self setHigherProgress:1.0 isCanSetZero:NO];
[self setLowerProgress:0.0 isCanSetZero:YES];
[self setMiddlerProgress:0.0 isCanSetZero:YES];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
else
{
//檔位從高到低
// NSInteger endAngle = 0.0;
// if ([_currentGearType isEqualToString:@"04"]) {
// endAngle = 10.0;
// }
// else
// {
// endAngle = [self.clockwiseArray[currentGearValue - 1] intValue] - 54;
// }
[self setHigherProgress:0.0 isCanSetZero:YES];
[self setLowerProgress:0.0 isCanSetZero:YES];
[self setMiddlerProgress:1.0 isCanSetZero:NO];
[self showAccessoryOnLine];
// self.lastGearType = self.currentGearType;
}
}
break;
default:
break;
}
}
//指示條賦值以及位置確定
- (void)showAccessoryOnLine
{
NSInteger currentGearValue = [self.currentGearType integerValue];
NSInteger endAngle = 0.0;
endAngle = [self transforAngleByGear:self.currentGearType];
// 1.添加圓點
if (currentGearValue == 1) {
CGFloat redDotCenterY = _circleCenter.y - sin(AngleToRadian2(endAngle)) * _outerCircleAadius;
CGFloat redDotCenterX = Width_Real(40) + (_outerCircleAadius - cos(AngleToRadian2(endAngle)) * _outerCircleAadius);
CGPoint dotCircleCenter = CGPointMake(redDotCenterX, redDotCenterY);
_circleIndictorView.indicatorLabel.text = [NSString stringWithFormat:@"%ld", currentGearValue];
_circleIndictorView.centerView.backgroundColor = kMainColor;
_circleIndictorView.center = dotCircleCenter;
// _circleIndictorView.indicatorLabel.center = dotCircleCenter;
}
else if (currentGearValue == 2)
{
CGFloat redDotCenterY = 0.0;
CGFloat redDotCenterX = 0.0;
redDotCenterY = _circleCenter.y - sin(AngleToRadian2(endAngle)) * _outerCircleAadius;
redDotCenterX = Width_Real(40) + (_outerCircleAadius - cos(AngleToRadian2(endAngle)) * _outerCircleAadius);
CGPoint dotCircleCenter = CGPointMake(redDotCenterX, redDotCenterY);
_circleIndictorView.indicatorLabel.text = [NSString stringWithFormat:@"%ld", currentGearValue];
_circleIndictorView.centerView.backgroundColor = HEXCOLOR(0xFFE86A);
_circleIndictorView.center = dotCircleCenter;
// _circleIndictorView.indicatorLabel.center = dotCircleCenter;
}
else if (currentGearValue == 3)
{
CGFloat redDotCenterY = 0.0;
CGFloat redDotCenterX = 0.0;
redDotCenterY = _circleCenter.y - sin(AngleToRadian2(endAngle)) * _outerCircleAadius;
redDotCenterX = Width_Real(40) + (_outerCircleAadius - cos(AngleToRadian2(endAngle)) * _outerCircleAadius);
CGPoint dotCircleCenter = CGPointMake(redDotCenterX, redDotCenterY);
_circleIndictorView.indicatorLabel.text = [NSString stringWithFormat:@"%ld", currentGearValue];
_circleIndictorView.centerView.backgroundColor = HEXCOLOR(0xFF7B4B);
_circleIndictorView.center = dotCircleCenter;
// _circleIndictorView.indicatorLabel.center = dotCircleCenter;
}
}
#pragma mark - 設(shè)置進(jìn)度條的進(jìn)度
- (void)setLowerProgress:(CGFloat)progress isCanSetZero:(BOOL)setZero {
if (progress > 1.0) {
_lowProgress = 1.0;
return;
}
if (!setZero) {
if (progress < AngleToRadian2(10)/AngleToRadian2(56)) {
_lowProgress = progress;
return;
}
}
_lowProgress = progress;
_startAngle = M_PI;
_endAngle = _startAngle + _lowProgress * AngleToRadian2(56);
UIBezierPath *topPath = [UIBezierPath bezierPathWithArcCenter:_circleCenter radius:_outerCircleAadius startAngle:_startAngle endAngle:_endAngle clockwise:YES];
_lowTopLayer.path = topPath.CGPath;
}
- (void)setMiddlerProgress:(CGFloat)progress isCanSetZero:(BOOL)setZero
{
if (progress > 1.0) {
_middleProgress = 1.0;
return;
}
if (!setZero) {
if (progress < AngleToRadian2(10)/AngleToRadian2(54)) {
_middleProgress = progress;
return;
}
}
_middleProgress = progress;
_startAngle = M_PI + AngleToRadian2(63);
_endAngle = _startAngle + _middleProgress * AngleToRadian2(54);
UIBezierPath *topPath = [UIBezierPath bezierPathWithArcCenter:_circleCenter radius:_outerCircleAadius startAngle:_startAngle endAngle:_endAngle clockwise:YES];
_middleTopLayer.path = topPath.CGPath;
}
- (void)setHigherProgress:(CGFloat)progress isCanSetZero:(BOOL)setZero
{
if (progress > 1.0) {
_highProgress = 1.0;
return;
}
if (!setZero) {
if (progress < AngleToRadian2(6)/AngleToRadian2(56)) {
_highProgress = progress;
return;
}
}
_highProgress = progress;
_startAngle = M_PI + AngleToRadian2(124);
_endAngle = _startAngle + _highProgress * AngleToRadian2(56);
UIBezierPath *topPath = [UIBezierPath bezierPathWithArcCenter:_circleCenter radius:_outerCircleAadius startAngle:_startAngle endAngle:_endAngle clockwise:YES];
_highTopLayer.path = topPath.CGPath;
}