Ios 如何前后设置路径动画?
我已经设置了一个UIBezier路径的动画,以便在这样做的同时围绕一个圆并更改其笔划颜色。当它沿着相反的方向旋转时,我希望它沿着相反的方向旋转 以下是使其向前发展的代码:Ios 如何前后设置路径动画?,ios,objective-c,xcode,Ios,Objective C,Xcode,我已经设置了一个UIBezier路径的动画,以便在这样做的同时围绕一个圆并更改其笔划颜色。当它沿着相反的方向旋转时,我希望它沿着相反的方向旋转 以下是使其向前发展的代码: [CATransaction begin]; { [CATransaction setAnimationDuration: 3.0];//Dynamic Duration [CATransaction setCompletionBlock:^{ [tutoria
[CATransaction begin];
{
[CATransaction setAnimationDuration: 3.0];//Dynamic Duration
[CATransaction setCompletionBlock:^{
[tutorialCircle removeFromSuperlayer];
tutorialCircle.opacity = 0.0;
strokePart.opacity = 0.0;
[strokePart removeFromSuperlayer];
}];
const double portion = 1.0 / ((double)3);
for (NSUInteger i = 0; i < 3; i++)
{
strokePart = [[CAShapeLayer alloc] init];
strokePart.fillColor = [[UIColor clearColor] CGColor];
strokePart.frame = tutorialCircle.bounds;
strokePart.path = tutorialCircle.path;
strokePart.lineCap = tutorialCircle.lineCap;
strokePart.lineWidth = tutorialCircle.lineWidth;
if (i == 0) {
strokePart.strokeColor = [UIColor greenColor].CGColor;
}
else if (i == 1) {
strokePart.strokeColor = [UIColor orangeColor].CGColor;
}
else if (i == 2) {
strokePart.strokeColor = [UIColor redColor].CGColor;
}
strokePart.strokeStart = i * portion;
strokePart.strokeEnd = (i + 1) * portion;
[tutorialCircle addSublayer: strokePart];
animation = [CAKeyframeAnimation animationWithKeyPath: @"strokeEnd"];
NSArray* times = @[ @(0.0), // Note: This works because both the times and the stroke start/end are on scales of 0..1
@(strokePart.strokeStart),
@(strokePart.strokeEnd),
@(1.0) ];
NSArray* values = @[ @(strokePart.strokeStart),
@(strokePart.strokeStart),
@(strokePart.strokeEnd),
@(strokePart.strokeEnd) ];
animation.keyTimes = times;
animation.values = values;
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeForwards;
[animation setDelegate:self];
[strokePart addAnimation: animation forKey: @"whatever"];
}
}
[CATransaction commit];
[CATransaction begin];
{
[CatTransaction setAnimationDuration:3.0];//动态持续时间
[CATTransaction setCompletionBlock:^{
[tutorialCircle removeFromSuperlayer];
tutorialCircle.opacity=0.0;
strokePart.opacity=0.0;
[strokePart从SuperLayer移除];
}];
常数双部分=1.0/((双)3);
对于(整数i=0;i<3;i++)
{
strokePart=[[CAShapeLayer alloc]init];
strokePart.fillColor=[[UIColor clearColor]CGColor];
strokePart.frame=tutorialCircle.bounds;
strokePart.path=tutorialCircle.path;
strokePart.lineCap=tutorialCircle.lineCap;
strokePart.lineWidth=tutorialCircle.lineWidth;
如果(i==0){
strokePart.strokeColor=[UIColor greenColor].CGColor;
}
else如果(i==1){
strokePart.strokeColor=[UIColor orangeColor].CGColor;
}
else如果(i==2){
strokePart.strokeColor=[UIColor redColor].CGColor;
}
strokePart.strokeStart=i*部分;
strokePart.strokeEnd=(i+1)*部分;
[教程循环添加子层:strokePart];
动画=[CAKeyframeAnimation animationWithKeyPath:@“strokeEnd”];
NSArray*times=@[@(0.0),//注意:这是因为时间和笔划开始/结束的刻度都是0..1
@(strokePart.strokeStart),
@(strokePart.strokeEnd),
@(1.0) ];
NSArray*值=@[@(strokePart.strokeStart),
@(strokePart.strokeStart),
@(strokePart.strokeEnd),
@(strokePart.strokeEnd)];
animation.keyTimes=次;
animation.values=值;
animation.removedOnCompletion=是;
animation.fillMode=kCAFillModeForwards;
[动画设置代理:self];
[strokePart addAnimation:animation forKey:@“任意”];
}
}
[CATransaction-commit];
因此,在第一个动画的animationDidStop委托方法中,我知道我会调用第二个动画使其后退,但是,我正在努力创建使其后退的动画。您尝试过吗
animation.autoreverses=YES
是的,它几乎完全符合我的要求,但当它返回时会闪烁不同的颜色