【发布时间】:2019-11-05 17:33:43
【问题描述】:
我刚刚使用最新版本的 CorePlot(v2.3,我之前运行的版本
final class GraphView: CPTGraphHostingView, CPTPlotDataSource {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configureGraph()
...
}
fileprivate func configureGraph() {
// Graph theme
graph.apply(CPTTheme(named: .plainWhiteTheme))
// Hosting view
self.hostedGraph = graph
// Plot Space
plotSpace = graph.defaultPlotSpace as! CPTXYPlotSpace
}
我注意到继承 UIView 而不是 CPTGraphHostingView 适用于新版本:
final class GraphView: UIView, CPTPlotDataSource {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configureGraph()
...
}
fileprivate func configureGraph() {
// Graph theme
graph.apply(CPTTheme(named: .plainWhiteTheme))
// Hosting view
let hostingView = CPTGraphHostingView(frame: self.frame)
hostingView.hostedGraph = graph
self.addSubview(hostingView)
// Plot Space
plotSpace = graph.defaultPlotSpace as! CPTXYPlotSpace
}
在大多数情况下都可以,但我的一个图表位于 ScrollView(启用分页)上,因此在这种情况下为 hostingView 获取 self.frame 并不容易。
我在这个新版本中遗漏了什么吗?
谢谢!
【问题讨论】:
标签: ios swift uiview subclass core-plot