【发布时间】:2021-10-29 01:07:33
【问题描述】:
在我的应用程序中,viewdidLoad() 使用 UIBezierPath 显示绿色 UIBezierPath 绘制线。
但稍后在程序中,事件回调使用相同的 UIBezierPath 删除所有点并在绿色旁边显示红线。
但是,它所做的只是在同一位置将绿线变为红色。
最终,我想使用 UIBezierPath 来显示一个不断变化的多线图—— 即:每秒删除以前的多线图并显示更新的多线图。
显示绿线的代码......................
var sensor_plot_UIBezierPath = UIBezierPath()
var sensor_plot_CAShapeLayer = CAShapeLayer()
override func viewDidLoad()
{
sensor_plot_UIBezierPath.move(to: CGPoint( x: 100,
y: 100))
sensor_plot_UIBezierPath.addLine( to: CGPoint( x: 200,
y: 200 ) )
init_app_display()
...start background events...
}
func init_app_display()
{
sensor_plot_CAShapeLayer.path = sensor_plot_UIBezierPath.cgPath
sensor_plot_CAShapeLayer.fillColor = UIColor.clear.cgColor // doesn't matter
sensor_plot_CAShapeLayer.strokeColor = UIColor.green.cgColor
sensor_plot_CAShapeLayer.lineWidth = 3.0
view.layer.addSublayer( sensor_plot_CAShapeLayer )
}
应该在它旁边显示红线的代码..................
(但实际上将初始绿线变为红色,在同一位置 - 第一行旁边没有第二行)
...display_plot_update() is called by event from background thread (specifically, BLE event didUpdateValueFor)
func display_plot_update()
{
DispatchQueue.main.async
{
self.sensor_plot_UIBezierPath.removeAllPoints()
self.sensor_plot_UIBezierPath.move(to: CGPoint( x: 110,
y: 100))
self.sensor_plot_UIBezierPath.addLine( to: CGPoint( x: 210,
y: 200 ) )
self.sensor_plot_CAShapeLayer.strokeColor = UIColor.red.cgColor
}
}
【问题讨论】:
-
你为什么在视图控制器下玩
UIBezierPath和CAShapeLayer?一个叫“init_app_display”的人是从哪里来的?
标签: ios swift uibezierpath