swift - SCIMetalRenderSurface 将保持为空
问题描述
我正在尝试在一个小测试项目中使用金属支架。我有以下几行来启用金属:
if SCIChartSurface.isMetalSupported {
sciChartSurface.renderSurface = SCIMetalRenderSurface(frame: sciChartSurface.bounds)
} else {
sciChartSurface.renderSurface = SCIOpenGLRenderSurface(frame: sciChartSurface.bounds)
}
表面一直是空的,直到我移除
sciChartSurface.renderSurface = SCIMetalRenderSurface(frame: sciChartSurface.bounds)
行——或者换句话说,我使用 OpenGL。然后图表将正确呈现。我正在使用 iPhoneX(不是模拟器)。
谢谢您的支持!
这是完整的代码墙
import UIKit
import SciChart
import SnapKit
class ViewController: UIViewController {
// MARK: - UIElements
private var sciChartSurface: SCIChartSurface!
// MARK: - Vars
private var series: SCIXyDataSeries?
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupSurface()
setupData()
renderData()
}
// MARK: - Chart
private func setupSurface() {
// Create a SCIChartSurface. This is a UIView so can be added directly to the UI
sciChartSurface = SCIChartSurface.init(frame: view.bounds)
sciChartSurface.debugWhySciChartDoesntRender = true
view.addSubview(sciChartSurface)
// Detect metal with this static property
if SCIChartSurface.isMetalSupported {
sciChartSurface.renderSurface = SCIMetalRenderSurface(frame: sciChartSurface.bounds)
} else {
sciChartSurface.renderSurface = SCIOpenGLRenderSurface(frame: sciChartSurface.bounds)
}
sciChartSurface.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
sciChartSurface.translatesAutoresizingMaskIntoConstraints = true
sciChartSurface.backgroundColor = .gray
// Create an XAxis and YAxis. This step is mandatory before creating series
let xAxis = SCICategoryNumericAxis()
setup(axis: xAxis)
sciChartSurface.xAxes.add(xAxis)
let yAxis = SCINumericAxis()
setup(axis: yAxis)
sciChartSurface.yAxes.add(yAxis)
}
private func setup(axis: SCIAxisBase) {
let axisStyle = SCIAxisStyle()
let majorPen = SCISolidPenStyle(colorCode: 0xFF393532, withThickness: 0.5)
let minorPen = SCISolidPenStyle(colorCode: 0xFF262423, withThickness: 0.5)
let textFormat = SCITextFormattingStyle()
textFormat.fontSize = 16
axisStyle.majorTickBrush = majorPen
axisStyle.majorGridLineBrush = majorPen
axisStyle.gridBandBrush = SCISolidBrushStyle(colorCode: 0xE1232120)
axisStyle.minorTickBrush = minorPen
axisStyle.minorGridLineBrush = minorPen
axisStyle.labelStyle = textFormat
axisStyle.drawMinorGridLines = true
axisStyle.drawMajorBands = true
axis.style = axisStyle
}
private func setupData() {
series = SCIXyDataSeries(xType: .int16, yType: .int16)
TestData.testData.forEach { (testData) in
let xGeneric = SCIGenericType(type: .int16, .init(int32Data: testData.x))
let yGeneric = SCIGenericType(type: .int16, .init(int32Data: testData.y))
series?.appendX(xGeneric, y: yGeneric)
}
}
private func renderData() {
let renderSeries = SCIFastColumnRenderableSeries()
renderSeries.dataSeries = series
sciChartSurface.renderableSeries.add(renderSeries)
}
}
struct TestData {
var x: Int32
var y: Int32
static let testData = [TestData(x: 2017, y: 5),
TestData(x: 2018, y: 8),
TestData(x: 2019, y: 2),
TestData(x: 2020, y: 9)]
}
解决方案
推荐阅读
- validation - 在 Go 中重用或转换结构以进行验证、API 结果和 DB 保存
- php - 存储在表中,Laravel
- c# - ImageMagick gif 创建速度很慢(~40 秒)
- html - 如何将两个 div 水平并排放置,其中一个是可折叠的?
- angular - '可观察的
' 不可分配给类型 'Hero[]' - vba - 需要对象错误“424” - 自动每日刷新
- hyperledger-fabric - Hyperledger composer-rest-server 关联多张卡片
- elasticsearch - ElasticSearch:布尔下嵌套查询的 Inner_hits - 支持吗?
- c - pthread_kill() 使用危险吗?
- cassandra - Cassandra Datastax cpp-driver - 回调似乎使用 1 个线程