Goal
An NSTextView that, upon new lines, expands its frame vertically to force a SwiftUI parent view to render again (i.e., expand a background panel that's under the text + push down other content in VStack). The parent view is already wrapped in a ScrollView. Since the SwiftUI TextEditor is ugly and under-featured, I'm guessing several others new to MacOS will wonder how …
我的问题 如何从 QLThumbnailGenerator.shared.generateRepresentations(for: ... ) 返回 cgImage?
我的挂断/尝试(下面的代码) 我的尝试有一个函数(第 13 行),它返回 ListView 条目的 CGImage(第 39 行)。我尝试使用空的 CGImage(第 18 行),但它的初始化参数令人困惑,并且对于简单的缩略图来说似乎过多。我可能会错误地处理这个问题。
注释 使用 CGImage,因此相同的代码可以同时适用于 iOS 和 MacOS Catalyst。(在 WWDC 2019 第 719 场会议中看到了这一点。)我尝试但未能从以下位置收集答案: - https://developer.apple.com/documentation/quicklookthumbnailing/creating_quick_look_thumbnails_to_preview_files_in_your_app - https://forums.developer.apple.com/message /375807
道歉/感谢 感谢您的耐心,因为答案可能很明显,而且我的词汇量可能不够。我愚蠢的大脑在没有一点实践经验的情况下就忽略了讲座,所以我从零编程知识开始了第一个应用程序作为隔离爱好。之后我会回到理论讲座。
结果视图.swift
import SwiftUI
import MobileCoreServices
import Combine
import QuickLookThumbnailing
import CoreImage
import UIKit
struct ResultsView: View {
@EnvironmentObject var parsedScreeningData: ParsedScreeningData
@EnvironmentObject var search: Search
func generateThumbnail(ofThis: String) -> CGImage {
let url = self.search.libraryFolder.appendingPathComponent(ofThis)
let size: CGSize = CGSize(width: 68, height: …Run Code Online (Sandbox Code Playgroud)