无法再在CorePlot(v2.3)中子类化CPTGraphHostingView吗?

我刚刚使用最新版本的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(启用了分页)上,因此在这种情况下为self.frame获取hostingView并不容易。 我在这个新版本中缺少什么吗? 谢谢!

SinoDinosaur 回答:无法再在CorePlot(v2.3)中子类化CPTGraphHostingView吗?

在调整托管视图的大小时使用bounds,而不是frame

let hostingView = CPTGraphHostingView(frame: self.bounds)
,

因此,根据Eric的答案,我删除了子类,并仅向托管视图添加了约束:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
本文链接:https://www.f2er.com/3157568.html

大家都在问