gpt4 book ai didi

ios - 画线然后删除它

转载 作者:行者123 更新时间:2023-11-29 03:02:29 25 4
gpt4 key购买 nike

使用 iOS 版 Xcode,我对一条绘制的线进行了动画处理。我希望几乎立即删除它(或消失)。我尝试重复代码,并将颜色设置为清除(测试为红色),因为我的背景是网格图案。但我只画了最后一条彩色线。关于按顺序绘制线条有什么想法吗?

{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0.0,100.0)];
[path addLineToPoint:CGPointMake(150.0, 100.0)];
[path addLineToPoint:CGPointMake(155.0, 50.0)];
[path addLineToPoint:CGPointMake(160.0, 150.0)];
[path addLineToPoint:CGPointMake(165.0, 100.0)];
[path addLineToPoint:CGPointMake(350.0, 100.0)];


CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.view.bounds;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor greenColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 2.0f;
pathLayer.lineJoin = kCALineJoinBevel;

[self.view.layer addSublayer:pathLayer];

CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 1.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
}

谢谢

最佳答案

添加:

    pathAnimation.autoreverses = true;
pathAnimation.removedOnCompletion = false;
pathAnimation.fillMode = kCAFillModeForwards;

您还可能希望使用动画委托(delegate)函数在完成时移除图层。

或者,如果您想要在动画反转之前延迟(甚至是轻微的延迟),或者想要以不同于反转动画的方式淡出它,您可以使用 CAAnimationGroup 在同一时间轴上执行一系列动画。

关于ios - 画线然后删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com