【发布时间】:2016-10-13 20:24:12
【问题描述】:
我在for 循环中更改CAShapeLayer 的路径,但它只显示循环的最后结果。我知道,我可以用 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;
}
辅助方法
+ (UIBezierPath *)getCirclePathAppendedWithCirclePathWithRadius:(CGFloat)radius andFrame:(CGRect)frame {
UIBezierPath *backgroundPath = [UIBezierPath bezierPathWithRect:frame];
[backgroundPath appendPath:[self getCirclePathWithRadius:radius andFrame:frame]];
return backgroundPath;
}
+ (UIBezierPath *)getCirclePathWithRadius:(CGFloat)radius andFrame:(CGRect)frame {
CGRect rect = frame;
UIBezierPath *circlePath;
circlePath = [UIBezierPath bezierPathWithArcCenter:(CGPoint){rect.size.width/2, rect.size.height/2} radius:radius startAngle:0 endAngle:M_PI*2 clockwise:YES];
return circlePath;
}
【问题讨论】:
-
你打算用这个 for 循环实现什么。它不会为任何东西设置动画。如果你设置一个变量百万次,最后你会得到最后一个值,对吧?这里也一样
-
我正在尝试根据设备位置绘制布局(使用 CoreMotion)。
标签: ios objective-c animation cashapelayer cgpath