tableView下拉时如何根据偏移量画圆

How to draw a circle according to the offset when drop down the tableView

  1. 我知道怎么根据偏移量画圆了
  2. 如果我下拉 tableView 的速度太快看不到绘制的过程,所以我想slower.How完成吗?谢谢。

这是我的circle.m
属性进度为偏移量(0.0~1.0)。

- (void)drawRect:(CGRect)rect {
    [WMFontColor888888 setStroke];
    CGFloat startAngle = - M_PI * 80 / 180;
    CGFloat step = 0.0;
    step = 33 * M_PI/18 * self.progress;
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2) radius:self.bounds.size.width / 2 - 3 startAngle:startAngle endAngle:startAngle + step  clockwise:YES];
    path.lineWidth = 1.5;
    path.lineCapStyle = kCGLineCapRound;
    path.lineJoinStyle = kCGLineJoinRound;
    [path stroke];

  }

如果深入到层级,可以子类化CAShapeLayer并使用-[CAShapeLayer strokeStart]-[CAShapeLayer strokeEnd]。然后,您只需将您的 CG 代码移动到 -drawInContext:

示例:

@implementation MyView

- (Class)layerClass
{
    return [MyCircleLayer class];
}

- (void)setProgress:(CGFloat)progress
{
    MyCircleLayer *layer = (id)self.layer;
    [layer setProgress:progress];
}

@end


@interface MyCircleLayer : CAShapeLayer
@property (nonatomic, assign) CGFloat progress;
@end

@implementation MyCircleLayer

// Vary strokeStart/strokeEnd based on where or how you want to animate the drawing

- (void)setProgress:(CGFloat)progress
{
    _progress = progress;
    /**
      Constantly updating strokeStart/strokeEnd should queue up redraws and
      should draw fluidly, but this could be delayed with an interval or via layer animation
    */
    [self setStrokeEnd:progress];
}

- (void)drawInContext:(CGContextRef)ctx
{
    [WMFontColor888888 setStroke];
    CGFloat startAngle = - M_PI * 80 / 180;
    CGFloat step = 0.0;
    // Draw the full circle
    ...
    [path stroke];
}