首页 > 代码库 > QQ去除未读状态的动画

QQ去除未读状态的动画

QQ去除未读状态的动画

by 伍雪颖

技术分享
github代码

- (void)drawRect:(CGRect)rect {
   
switch (_state) {
       
caseSRSlimeStateNormal:
        {
           
float percent =1 -distansBetween(_startPoint ,_toPoint) /_viscous;
           
if (percent ==1) {
               
CGContextRef context =UIGraphicsGetCurrentContext();
               
UIBezierPath *path = [UIBezierPathbezierPathWithRoundedRect:CGRectMake(_startPoint.x - _radius,_startPoint.y -_radius,2*_radius,2*_radius)
                                                               
cornerRadius:_radius];
                [
selfsetContext:contextpath:path];
               
CGContextDrawPath(context,kCGPathFillStroke);
            }
else {
               
CGFloat startRadius =_radius * (kStartTo + (1-kStartTo)*percent);
               
CGFloat endRadius =_radius * (kEndTo + (1-kEndTo)*percent);
               
CGContextRef context =UIGraphicsGetCurrentContext();
               
               
UIBezierPath *path = [selfbodyPath:startRadius
                                               
end:endRadius
                                           
percent:percent];
                [
selfsetContext:contextpath:path];
               
CGContextDrawPath(context,kCGPathFillStroke);
               
if (percent <=0) {
                   
_state =SRSlimeStateShortening;
                    [
selfscaling];
                }
            }
        }
           
break;
       
caseSRSlimeStateShortening:
        {
           
_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 = [selfbodyPath:startRadius
                                               
end:endRadius
                                           
percent:percent];
                [
selfsetContext:contextpath:path];
               
CGContextDrawPath(context,kCGPathFillStroke);
            }
else {
               
self.hidden =YES;
               
_state =SRSlimeStateMiss;
            }
        }
           
break;
       
default:
           
break;
    }
}


QQ去除未读状态的动画