Swift ui macos ProgressView未解析标识符的使用';ProgressView';
我试图在macos项目中添加ProgressView,但它给了我以下错误,在internet上我找不到任何解决方案Swift ui macos ProgressView未解析标识符的使用';ProgressView';,swift,macos,swiftui,loader,Swift,Macos,Swiftui,Loader,我试图在macos项目中添加ProgressView,但它给了我以下错误,在internet上我找不到任何解决方案 有人能帮我吗?此ProgressView仅适用于MacOs 11,您可以在该链接中看到 您可以使用NSProgressIndicator并将其包装成NSViewRepresentable,如下所示: import Swift import SwiftUI public struct ActivityIndicator { public enum Style {
有人能帮我吗?此ProgressView仅适用于MacOs 11,您可以在该链接中看到 您可以使用
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
导入Swift
导入快捷键
公共结构活动指示器{
公共枚举样式{
病例培养基
大箱子
}
私有变量已初始化:Bool=true
私有变量样式:样式?=style.medium
公共init(){
}
}
#如果操作系统(macOS)
进口可可
导入应用程序包
扩展活动指示器:NSViewRepresentable{
公共类型别名上下文=NSViewRepresentableContext
公共类型别名NSViewType=NSPROGRESINDICATOR
public func makeNSView(上下文:context)->NSViewType{
设nsView=NSProgressIndicator()
nsView.isIndeterminate=true
nsView.style=.spining
nsView.sizeToFit()
nsView.layer?.transform=CATTransformM3dMakeScale(1.0,0.6,0.0);
nsView.controlSize=.small
返回nsView
}
public func updateNSView(unsview:NSViewType,context:context){
isAnimated?nsView.startAnimation(self):nsView.stopAnimation(self)
}
}
#恩迪夫
此ProgressView仅适用于MacOs 11,您可以在此链接中看到
您可以使用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
导入Swift
导入快捷键
公共结构活动指示器{
公共枚举样式{
病例培养基
大箱子
}
私有变量已初始化:Bool=true
私有变量样式:样式?=style.medium
公共init(){
}
}
#如果操作系统(macOS)
进口可可
导入应用程序包
扩展活动指示器:NSViewRepresentable{
公共类型别名上下文=NSViewRepresentableContext
公共类型别名NSViewType=NSPROGRESINDICATOR
public func makeNSView(上下文:context)->NSViewType{
设nsView=NSProgressIndicator()
nsView.isIndeterminate=true
nsView.style=.spining
nsView.sizeToFit()
nsView.layer?.transform=CATTransformM3dMakeScale(1.0,0.6,0.0);
nsView.controlSize=.small
返回nsView
}
public func updateNSView(unsview:NSViewType,context:context){
isAnimated?nsView.startAnimation(self):nsView.stopAnimation(self)
}
}
#恩迪夫
您使用的SDK和部署目标是什么?它仅在SwiftUI 2.0/macOS 11.xCode:Version 11.6、macOS:10.15.4中可用,您使用的SDK和部署目标是什么?它仅在SwiftUI 2.0/macOS 11.xCode:Version 11.6、macOS:10.15.4中可用