| 关键词: nbsp percent context radius path UIBezierPath startRadius endRadius CGContextDrawPat kStartTo |
github代码- (void)drawRect:(CGRect)rect { switch (_state) { case SRSlimeStateNormal: { float percent = 1 - distansBetween(_startPoint , _toPoint) / _viscous; if (percent == 1) { CGContextRef context = UIGraphicsGetCurrentContext(); UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(_startPoint.x - _radius,_startPoint.y - _radius, 2*_radius, 2*_radius) cornerRadius:_radius]; [self setContext:context path:path]; CGContextDrawPath(context, kCGPathFillStroke); }else { CGFloat startRadius = _radius * (kStartTo + (1-kStartTo)*percent); CGFloat endRadius = _radius * (kEndTo + (1-kEndTo)*percent); CGContextRef context = UIGraphicsGetCurrentContext(); UIBezierPath *path = [self bodyPath:startRadius end:endRadius percent:percent]; [self setContext:context path:path]; CGContextDrawPath(context, kCGPathFillStroke); if (percent <= 0) { _state = SRSlimeStateShortening; [self scaling]; } } } break; case SRSlimeStateShortening: { _toPoint = CGPointMake((_toPoint.x - _startPoint.x)*0.8 + _startPoint.x, (_toPoint.y - _startPoint.y)*0.8 + _startPoint.y); float p = distansBetween(_startPoint, _toPoint) / _viscous; float percent =1 -p; float r = _radius * p; if (p > 0.01) { CGFloat startRadius = r * (kStartTo + (1-kStartTo)*percent); CGContextRef context = UIGraphicsGetCurrentContext(); CGFloat endRadius = r * (kEndTo + (1-kEndTo)*percent) * (1+percent / 2); UIBezierPath *path = [self bodyPath:startRadius end:endRadius percent:percent]; [self setContext:context path:path]; CGContextDrawPath(context, kCGPathFillStroke); }else { self.hidden = YES; _state = SRSlimeStateMiss; } } break; default: break; }} |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|