美文网首页
iOS简单的动画绘制 #CABasicAnimation# #

iOS简单的动画绘制 #CABasicAnimation# #

作者: Nirvana_icy | 来源:发表于2015-03-02 17:26 被阅读1033次
    - (void)drawError
    {
        [_logoView removeFromSuperview];
        _logoView = [[UIView alloc] initWithFrame:CGRectMake(([self getSelfSize].width-Simble_SIZE)/2, Simble_TOP, Simble_SIZE, Simble_SIZE)];
        
        
        // 绘制轨迹 with UIBezierPath
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(Simble_SIZE/2, Simble_SIZE/2) radius:Simble_SIZE/2 startAngle:0 endAngle:M_PI*2 clockwise:YES];
        
        CGPoint p1 =  CGPointMake(Simble_SIZE/4, Simble_SIZE/4);
        [path moveToPoint:p1];
        
        CGPoint p2 =  CGPointMake(Simble_SIZE/4*3, Simble_SIZE/4*3);
        [path addLineToPoint:p2];
        
        CGPoint p3 =  CGPointMake(Simble_SIZE/4*3, Simble_SIZE/4);
        [path moveToPoint:p3];
        
        CGPoint p4 =  CGPointMake(Simble_SIZE/4, Simble_SIZE/4*3);
        [path addLineToPoint:p4];
        
        
        CAShapeLayer *layer = [[CAShapeLayer alloc] init];
        layer.lineWidth = 5;
        layer.path = path.CGPath;
        layer.fillColor = [UIColor clearColor].CGColor;
        layer.strokeColor = [UIColor redColor].CGColor;
        
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:NSStringFromSelector(@selector(strokeEnd))];
        animation.fromValue = @0;
        animation.toValue = @1;
        animation.duration = 0.5;
        [layer addAnimation:animation forKey:NSStringFromSelector(@selector(strokeEnd))];
        
        [_logoView.layer addSublayer:layer];
        [self addSubview:_logoView];
    }
    

    相关文章

      网友评论

          本文标题:iOS简单的动画绘制 #CABasicAnimation# #

          本文链接:https://www.haomeiwen.com/subject/ygcmxttx.html