Ios 更改CAShapeLayer';for循环中的s路径无效
我正在为循环更改CAShapeLayer在Ios 更改CAShapeLayer';for循环中的s路径无效,ios,objective-c,animation,cashapelayer,cgpath,Ios,Objective C,Animation,Cashapelayer,Cgpath,我正在为循环更改CAShapeLayer在中的路径,但它只显示循环的最后结果。我知道,我可以通过CABasicAnimation做到这一点,但我需要以这种方式改变路径。有什么办法吗 UIBezierPath *path = [ShapeManager getCirclePathAppendedWithCirclePathWithRadius:radius
中的路径,但它只显示循环的最后结果。我知道,我可以通过CABasicAnimation做到这一点,但我需要以这种方式改变路径。有什么办法吗
UIBezierPath *path = [ShapeManager getCirclePathAppendedWithCirclePathWithRadius:radius
andFrame:self.view.bounds];
self.layer.fillRule = kCAFillRuleEvenOdd;
self.layer.fillColor = [UIColor grayColor].CGColor;
self.layer.opacity = 0.5;
self.layer.path = path.CGPath;
[self.view.layer addSublayer:self.layer];
for (int i = 1; i < 100; ++i) {
path = [ShapeManager getCirclePathAppendedWithCirclePathWithRadius:self.view.bounds.size.width-i
andFrame:self.view.bounds];
self.layer.path = path.CGPath;
}
你使用卡巴斯基信息是对的
删除你的for
循环,它不会执行此任务李>
为path
添加cabasicanitation
,并在其中插入值。此代码在viewDidLoad
方法中只能调用一次:
更新:
在最后一行中,您将速度值设置为0,因为您将手动设置动画进度:
这假定动画持续时间为1.0。否则,您需要设置
layer.timeOffset = (CFTimeInterval)(progress * totalDuration);
现在,只需根据更新后的值设置运动中的进度回调。使用此for循环,您将实现什么。它不会给任何东西设置动画。如果你设置一个变量一百万次,最后你会得到最后一个值,对吗?同样的,我尝试根据设备位置(使用CoreMotion)绘制布局。我已经尝试过了。但我需要根据设备位置绘制ui。我以0.01的时间间隔接收设备运动更新,我需要非常快地制作动画,所以您希望在每次调用回调时根据运动值更新路径(~60次/秒)?是,我就是这么想的need@passingnil您是否尝试过使用timeOffset
和layer.speed=0
的解决方案?@passingnil我们终于做到了:)
UIBezierPath *fromPath = [self.class getCirclePathAppendedWithCirclePathWithRadius:self.view.bounds.size.width andFrame:self.view.bounds];
UIBezierPath *toPath = [self.class getCirclePathAppendedWithCirclePathWithRadius:self.view.bounds.size.width-99 andFrame:self.view.bounds];
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.fromValue = (id)fromPath.CGPath;
animation.toValue = (id)toPath.CGPath;
animation.duration = 1;
[layer addAnimation:animation forKey:@"pathAnimation"];
layer.speed = 0;
@property (nonatomic, assign) double progress;
- (void) setProgress: (double) progress {
_progress = progress;
layer.timeOffset = (CFTimeInterval)progress;
}
layer.timeOffset = (CFTimeInterval)(progress * totalDuration);