【问题标题】:Handling rotation when using SwiftCharts使用 SwiftCharts 时处理旋转
【发布时间】:2025-12-25 09:00:15
【问题描述】:

我正在为 Swift 4 使用 SwiftCharts。我无法弄清楚如何以横向启动应用程序或处理从纵向到横向的旋转来正确显示简单的图表。谁能指点我有关如何处理非纵向实现的示例或文档?

提前致谢

【问题讨论】:

    标签: swiftcharts


    【解决方案1】:

    在 RangedAxisExample 中找到这个。

    let orientation = UIApplication.shared.statusBarOrientation
        guard (lastOrientation.map{$0.rawValue != orientation.rawValue} ?? true) else {return}
    
        lastOrientation = orientation
    
        guard let chart = chart else {return}
        for view in chart.view.subviews {
            view.removeFromSuperview()
        }
        self.drawChart() //  my chart code here
    
        chart.view.setNeedsDisplay()
    

    【讨论】: