gpt4 book ai didi

ios - CAShapeLayer 描边看起来已重置

转载 作者:行者123 更新时间:2023-11-29 05:54:09 34 4
gpt4 key购买 nike

我有一个简单的循环进度 View ,当下载文件时该 View 会被填充。大多数时候它会按预期工作,但有时它会“重置” - 它会填充到某个部分,通常填充到 100% 之前的最后一部分,然后突然变为 0%,然后达到 100%。这是它的实现:

@interface CircleView()

@property (nonatomic, strong) CAShapeLayer *circleLayer;

@end


@implementation CircleView

-(instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];

if (self) {
self.backgroundColor = UIColor.clearColor;

UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width / 2., self.frame.size.height / 2.0) radius: (self.frame.size.width - 10) / 2 startAngle:0.0 endAngle:M_PI * 2 clockwise:YES];

CAShapeLayer *downLayer = [[CAShapeLayer alloc] init];
downLayer.path = circlePath.CGPath;
downLayer.fillColor = UIColor.clearColor.CGColor;
downLayer.strokeColor = UIColor.lightGrayColor.CGColor;
downLayer.lineWidth = 15.0;

downLayer.strokeEnd = 1.0;

self.circleLayer = [[CAShapeLayer alloc] init];
self.circleLayer.path = circlePath.CGPath;
self.circleLayer.fillColor = UIColor.clearColor.CGColor;
self.circleLayer.strokeColor = UIColor.tubeWayRed.CGColor;
self.circleLayer.lineWidth = 15.0;

self.circleLayer.strokeEnd = 0.0;

[self.layer addSublayer:downLayer];
[self.layer addSublayer: self.circleLayer];
}

return self;
}

-(void)animateCircleToPart:(CGFloat)toPart {
self.circleLayer.strokeEnd = toPart;
}

-(void)resetCircle {
NSLog(@"Resetting circle");
[CATransaction begin];
[CATransaction setDisableActions:YES];
self.circleLayer.strokeEnd = 0;
[CATransaction commit];
}

@end

日志显示在达到 100% 之前,它不会被 reset 方法重置。有什么想法可能是错误的吗?谢谢。

问题消失了,在 [CATransaction begin] - [CATransaction commit] 调用中包装调用 self.circleLayer.StrokeEnd = toPart; ,例如这个:

-(void)animateCircleToPart: (CGFloat)toPart {
[CATransaction begin];
self.circleLayer.strokeEnd = toPart;
[CATransaction commit];
}

谁能解释一下为什么吗?

最佳答案

我的建议是这样的:

 -(void)animateCircleToPart:(CGFloat)toPart {
if (toPart > self.circleLayer.strokeEnd){
self.circleLayer.strokeEnd = toPart;}
}

关于ios - CAShapeLayer 描边看起来已重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55341950/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com