如何解决Swift UI MacOS ProgressView使用未解析的标识符'ProgressView'
我试图在macOS项目中添加一个ProgressView,但是它给我以下错误,在Internet上查找找不到任何解决方案。
有人可以帮我吗?
解决方法
此 ProgressView 仅适用于 MacOs 11,您可以在此链接中看到 https://developer.apple.com/documentation/swiftui/progressview
您可以使用 NSProgressIndicator
并将其包装成 NSViewRepresentable
,如下所示:
import Swift
import SwiftUI
public struct ActivityIndicator {
public enum Style {
case medium
case large
}
private var isAnimated: Bool = true
private var style: Style? = Style.medium
public init() {
}
}
#if os(macOS)
import Cocoa
import AppKit
extension ActivityIndicator: NSViewRepresentable {
public typealias Context = NSViewRepresentableContext<Self>
public typealias NSViewType = NSProgressIndicator
public func makeNSView(context: Context) -> NSViewType {
let nsView = NSProgressIndicator()
nsView.isIndeterminate = true
nsView.style = .spinning
nsView.sizeToFit()
nsView.layer?.transform = CATransform3DMakeScale(1.0,0.6,0.0);
nsView.controlSize = .small
return nsView
}
public func updateNSView(_ nsView: NSViewType,context: Context) {
isAnimated ? nsView.startAnimation(self) : nsView.stopAnimation(self)
}
}
#endif
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。