亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問該如何用代碼控制看到由點到線的效果呢?

請問該如何用代碼控制看到由點到線的效果呢?

瀟瀟雨雨 2023-05-01 15:11:08
有這么一個需求,需要在UILabel Text上點擊之后添加劃線效果,就是類似todo done那種。我知道簡單的劃線就是起點加重點坐標,連接成為一條線,但是如何用代碼控制看到由點到線的效果呢?CGContextSetLineWidth(context, 1);CGContextMoveToPoint(context, x, y);CGContextAddLineToPoint(context, x, y);CGContextStrokePath(context);謝謝!
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

主要是這兩個方法:

- (void)setupLayers
{    if (animationLayer != nil) {
        [animationLayer removeFromSuperlayer];
    }
    animationLayer = [CALayer layer];
    animationLayer.frame = self.bounds;
    [self.layer addSublayer:animationLayer];    
    CGPoint midLeft = CGPointMake(CGRectGetMinX(animationLayer.bounds), CGRectGetMidY(animationLayer.bounds));    CGPoint midRight = CGPointMake(CGRectGetMaxX(animationLayer.bounds), CGRectGetMidY(animationLayer.bounds));    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:midLeft];
    [path addLineToPoint:midRight];
    
    pathLayer = [CAShapeLayer layer];
    pathLayer.frame = animationLayer.bounds;
    pathLayer.geometryFlipped = YES;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [UIColor blackColor].CGColor;
    pathLayer.lineWidth = 2;
    [animationLayer addSublayer:pathLayer];
}

- (void)startAnimation
{
    [animationLayer removeAllAnimations];
    [pathLayer removeAllAnimations];    
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation.duration = 3.0;
    pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
    [pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
}
查看完整回答
反對 回復 2023-05-03
  • 1 回答
  • 0 關注
  • 226 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號