【发布时间】:2020-02-11 08:27:47
【问题描述】:
我正在为 iOS 构建一个图形应用程序。这是我的代码。
class Group {
/// All the shapes contained in the group
public var shapes: CurrentValueSubject<[Shape], Never>
/// The frame of the group
var frame: CurrentValueSubject<CGRect, Never>
/// The path to be calculated and displayed to users from the contained shapes
var cgPath: CurrentValueSubject<CGPath, Never>
}
class Shape {
var path: CurrentValueSubject<Path, Never> = .init(Path())
}
struct Path {
public var points = [CGPoint]()
}
所以,这就是我想要做的,但不知道如何使用 Combine 来做。
我想让Group 观察它自己的frame、shapes 和它的形状的path(我需要合并所有这些),所以每次它们改变时,我都可以计算出新的要显示的 CGPath 并将其分配给 cgPath 属性(绘制所有内容的 View 将观察到该属性)。
请让我知道这是否可行,或者是否有更好的方法来解决所有这些问题。
提前致谢。
【问题讨论】: