gpt4 book ai didi

ios - 如何在绘图中添加闪烁圆圈:inRect: method of UIView?

转载 作者:行者123 更新时间:2023-11-30 12:30:08 24 4
gpt4 key购买 nike

在我的自定义 UIView 和 draw:inRect 初始化程序中,我有以下代码:

override func draw(_ rect: CGRect) {
super.draw(rect)

//...

let axisPath = UIBezierPath()

axisPath.move(to: CGPoint(x: paddingHorizontal + 20, y: paddingVertical))
axisPath.addLine(to: CGPoint(x: leftOffset, y: bottomOffset))
axisPath.addLine(to: CGPoint(x: rect.width - paddingHorizontal, y: bottomOffset))
axisPath.lineWidth = 1

UIColor.black.set()
axisPath.stroke()

var currentIndex = 0

for yearData in data {

//...

let circle = UIBezierPath(roundedRect: CGRect(x: x - 4, y: y - 4, width: 8, height: 8), cornerRadius: 4)
circle.fill()
circle.stroke() //red circle, I need to make it blinking somehow
//...
}

//...
}

结果如下:

enter image description here

现在我需要让红色圆圈闪烁:)我该怎么做?

最佳答案

我会采取不同的方法。仅对图形的静态部分使用 draw(_:)

闪烁的红色圆圈应该是添加在图形 View 上的一个简单的小 subview 。使用重复的 UIView 动画,利用其 alpha 属性来淡入和淡出小圆圈 View 。

参见How do I get this fade animation to work?有关执行闪烁动画的示例。

关于ios - 如何在绘图中添加闪烁圆圈:inRect: method of UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43659967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com