ios - iOS 15:SwiftUI Canvas/TimelineView 糟糕的性能
问题描述
玩转 iOS 15 的新 Canvas/TimelineView。我尝试使用官方 WWDC 教程创建粒子系统,但无法解决与性能相关的问题。
这是代码:
struct MyView: View {
@State private var count = 32*32
var body: some View {
TimelineView(.animation) { timeline in
Canvas { context, size in
let now = timeline.date.timeIntervalSinceReferenceDate
for i in 0..<count {
context.fill(Ellipse().path(in: CGRect(x: size.width*0.01*Double(i), y: size.height*0.01*Double(i), width: 20.0, height: 20.0)), with: .color(.green))
}
}
}
}
}
它只画了 1024 个圆圈,但已经消耗了大约 20% 的模拟器 CPU 和 50% 的我的 iPhone 8 CPU。考虑到 iPhone 的强大功能和新框架的有效性,这是预期的行为吗?如果我需要超过 1024 个圆圈,我应该如何解决这个问题?
解决方案
推荐阅读
- excel - IsNull()、IsEmpty()、Application.WorksheetFunction.Istext() 为什么不能在组合框上工作?
- javascript - LocalStorage 图像加载 - 奇怪的行为
- apache-flink - 读取 csv 时使用 flink 的 NUMERIC_VALUE_ILLEGAL_CHARACTER
- java - java中字符串方法子字符串中的错误
- json - 具有指定格式的表到 JSON
- android - Pixel2 Oreo 8.1.0 版中的 BLE 扫描问题
- node.js - 对话流代理不从 HTTP 请求回调中输出文本
- arm - 如何解压缩 ARM“vmlinuz”内核?
- mysql - 如何在 MySQL 2008 中的日期时间 MM/DD/YYYY HH:MM:SS AM 中返回字符串“2016-06-27 05:29:39”
- ios - 在 Swift 中字符串的当前时间