by 伍雪颖

QQ去除未读状态的动画

- (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;
    }
}


相关文章:

  • 2021-05-18
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
  • 2021-11-29
  • 2021-10-21
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2021-10-20
  • 2022-12-23
  • 2021-11-23
  • 2021-06-04
  • 2021-12-16
  • 2021-06-25
相关资源
相似解决方案