Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为剪辑UIImage的UIBezierPath设置动画_Ios_Uiimage_Core Animation_Clipping_Uibezierpath - Fatal编程技术网

Ios 为剪辑UIImage的UIBezierPath设置动画

Ios 为剪辑UIImage的UIBezierPath设置动画,ios,uiimage,core-animation,clipping,uibezierpath,Ios,Uiimage,Core Animation,Clipping,Uibezierpath,我有一个看起来像甜甜圈的图像,并希望对其设置动画,使其看起来像是甜甜圈圈未完成(笔划未闭合)。这很难描述,但想象一个车速表,它达到100,你开50。我在UIGraphicsBeginImageContextWithOptions中的path和[path addClip]的帮助下完成了掩蔽,在这里我还渲染了UIImage 我现在的问题是,我可以或者如何设置路径的动画。我用一个cabasicanition和两条路径(第一条路径的startAngle和endAngle相同,第二条路径的endAngle

我有一个看起来像甜甜圈的图像,并希望对其设置动画,使其看起来像是甜甜圈圈未完成(笔划未闭合)。这很难描述,但想象一个车速表,它达到100,你开50。我在UIGraphicsBeginImageContextWithOptions中的path和[path addClip]的帮助下完成了掩蔽,在这里我还渲染了UIImage

我现在的问题是,我可以或者如何设置路径的动画。我用一个cabasicanition和两条路径(第一条路径的startAngle和endAngle相同,第二条路径的endAngle是所需的角度)尝试了它,其中“path”作为关键路径,但这不起作用


任何有用的东西;)

我使用
CABasicAnimation
使用

UIBezierPath *bezierPath = [self bezierPath];

CAShapeLayer *bezierLayer = [[CAShapeLayer alloc] init];

bezierLayer.path = bezierPath.CGPath;
bezierLayer.strokeColor = [UIColor redColor].CGColor;
bezierLayer.fillColor = [UIColor clearColor].CGColor;
bezierLayer.lineWidth = 5.0;
bezierLayer.strokeStart = 0.0;
bezierLayer.strokeEnd = 1.0;
[self.view.layer addSublayer:bezierLayer];

if (animate)
{
    CABasicAnimation *animateStrokeEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    animateStrokeEnd.duration = 1.0;
    animateStrokeEnd.fromValue = @0.0f;
    animateStrokeEnd.toValue = @1.0f;
    [bezierLayer addAnimation:animateStrokeEnd forKey:@"strokeEndAnimation"];
}

我建议设置一个CAShapeLayer,让shape层渲染你的甜甜圈形状。您应该能够将甜甜圈形状渲染为带有粗线的圆弧的CGPath

CAShapeLayer具有strokeStart和strokeEnd属性。两者的范围都在0.0到1.0之间。默认情况下,strokeStart为0.0(从起点开始),strokeEnd为1.0(绘制整个路径)。这些属性是可设置动画的

如果将strokeEnd从.75更改为1.0,则路径将仅绘制其3/4,并为绘制路径的最后1/4设置动画

我在gitHub上有一个项目,演示了如何在图像上使用形状层作为遮罩,以创建“时钟擦除”过渡。为此,我将弧上的线宽设置为如此之大,以至于形状完全填充框架矩形,而不是绘制圆环形状。在你的情况下,你会减少线的厚度,这样它就可以画出你的甜甜圈


单击应用程序中的“Mask Animation”(遮罩动画)按钮,查看正在工作的形状层动画。

你和我的方法非常相似。请注意,您可以直接更改图层的“strokeEnd”属性,并免费获得“隐式动画”,而无需创建CABasicAnimation对象。@Duncan如果您知道如何设置路径动画,那么我不确定是否遵循了问题所在。我不是在问问题。我想指出的是,您可以跳过cabasicaniation,只需更改strokeEnd属性。这会产生一个隐含的动画。我没有发布原始问题。你把我和线程启动程序搞混了吗?我使用了你的解决方案,因为这最终对我有效;)再次感谢!!!!