QQ去除未读状态的动画

QQ去除未读状态的动画

by 伍雪颖



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


原文地址:https://www.cnblogs.com/zfyouxi/p/5392156.html