- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
使用 this previous 中的答案,我未能在 CAShapeLayer
上设置闪烁笔画的动画效果线程,经过多次搜索后,我找不到使用 CABasicAnimation
为笔画设置动画的其他示例。
我想要做的是让我的 CAShapeLayer
脉冲在两种颜色之间。将 CABasicAnimation
用于不透明度效果很好,但 [CABasicAnimation animationWithKeyPath:@"strokeColor"]
让我望而却步,我很感激任何关于如何成功实现的建议。
CABasicAnimation *strokeAnim = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
strokeAnim.fromValue = (id) [UIColor blackColor].CGColor;
strokeAnim.toValue = (id) [UIColor purpleColor].CGColor;
strokeAnim.duration = 1.0;
strokeAnim.repeatCount = 0.0;
strokeAnim.autoreverses = NO;
[shapeLayer addAnimation:strokeAnim forKey:@"animateStrokeColor"];
// CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
// opacityAnimation.fromValue = [NSNumber numberWithFloat:0.0];
// opacityAnimation.toValue = [NSNumber numberWithFloat:1.0];
// opacityAnimation.duration = 1.0;
// opacityAnimation.repeatCount = 0.0;
// opacityAnimation.autoreverses = NO;
// [shapeLayer addAnimation:opacityAnimation forKey:@"animateOpacity"];
取消注释不透明度动画会导致预期的不透明度淡化。笔划动画不产生任何效果。隐式 strokeColor 更改按预期进行动画处理,但我想要记录确认 strokeColor 可以使用 CABasicAnimation 显式设置动画。
更新:具体问题是 shapeLayer.path 为 NULL。更正该问题已解决。
最佳答案
下面的代码非常适合我。 shapeLayer 描边路径的 lineWidth 是多少?这可能是问题所在吗?
- (void)viewDidLoad
{
[super viewDidLoad];
UIBezierPath * circle = [UIBezierPath bezierPathWithOvalInRect:self.view.bounds];
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
shapeLayer.path = circle.CGPath;
shapeLayer.strokeColor =[UIColor blueColor].CGColor;
[shapeLayer setLineWidth:15.0];
[self.view.layer addSublayer:shapeLayer];
CABasicAnimation *strokeAnim = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
strokeAnim.fromValue = (id) [UIColor redColor].CGColor;
strokeAnim.toValue = (id) [UIColor greenColor].CGColor;
strokeAnim.duration = 3.0;
strokeAnim.repeatCount = 0;
strokeAnim.autoreverses = YES;
[shapeLayer addAnimation:strokeAnim forKey:@"animateStrokeColor"];
}
让我知道它是否适合你...
关于objective-c - 使用 CABasicAnimation 为 CAShapeLayer 的 strokeColor 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12122636/
我想为 CAShapeLayer 的 strokeColor 设置动画,但在 CABasicAnimation 中我有两个值(from 和 to)。动画火时是否只支持两种颜色?例如,开始时我有 str
在这个 CG 教程挑战中,我们被要求在 for 循环中增加在 View 上绘制的圆圈的颜色。为此,我设置了一个带有颜色的数组,然后尝试通过使用递增的 i++ 移动到索引中的下一个对象来实现前循环内的颜
我正在使用 swift 4。 我写了下面的代码并尝试用笔画画一个圆。 但是,使用下面的代码我无法绘制我想要的圆。 问题是线是从圆心画到外围 (严格来说,是朝向'startAngle'属性的坐标点)。
我使用贝塞尔曲线创建了 body 图像图。 在我的 customView 中,我为每个 body 部位创建了大约 62 条贝塞尔曲线!最初所有这些都设置为默认颜色。当用户触摸这些路径中的任何一个时,我
我正在尝试为 CAShapeLayar 的 strokeColor 属性设置动画。我查看了文档,并指出它是一个可动画的属性。该代码用于动画 postion.y 但不是 strokeColor。我很乐意
我想绘制对角线 View 。 这是我的代码。 override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(anima
我使用六个参数(事件、非事件、有线、压缩、免费和总计)。我创建了一个 CAShapeLayer 类,并在其中创建了一个函数,我可以在其中绘制圆圈,只需添加参数即可。我制作了 CGPath 并在绘制圆圈
我已经动态添加了一个 CSS 类,如下所示: var style = document.createElement('style'); style.id = "highlightSegment"; v
我的问题是,当我尝试将透明设置为 FreeText 注释的 strokeColor 时,添加一个结果注释有黑色边框。 我尝试这样编码: this.addAnnot({ type: "FreeText"
我正在使用 CABasicAnimation 绘制我在数组中使用 CAShapeLayer 的所有 UIBezierPaths CAShapeLayer *shapeLayer = [CAShapeL
使用 this previous 中的答案,我未能在 CAShapeLayer 上设置闪烁笔画的动画效果线程,经过多次搜索后,我找不到使用 CABasicAnimation 为笔画设置动画的其他示例。
当我更改 SKShapeNode 的 .alpha 时,它的 stroke 显示自己好像节点的 .strokeColor 比它的 .fillColor 更亮。将 .lineWidth 设置为 0 会取
试图在 cardView 周围做一些边框(androidx.cardview.widget.CardView) 这是代码: 结果: 还尝试使用自定义形状作为背景( fix_border.xml )
添加我的代码。它正在添加一个带有另一个 alpha 的边框,如阴影。 let sliderLayer = CAShapeLayer() sliderLayer.fillColor = UICo
我是一名优秀的程序员,十分优秀!