【问题标题】:Swift ui macos ProgressView Use of unresolved identifier 'ProgressView'Swift ui macos ProgressView 使用未解析的标识符'ProgressView'
【发布时间】:2020-08-26 16:43:24
【问题描述】:

我正在尝试在 macOS 项目中添加 ProgressView,但它给了我以下错误,在互联网上查找我找不到任何解决方案。

谁能帮帮我?

【问题讨论】:

  • 您使用什么 SDK 和部署目标?它仅在 SwiftUI 2.0 / macOS 11 中可用。
  • xCode:版本 11.6,MacOs:10.15.4

标签: swift macos swiftui loader


【解决方案1】:

此 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

【讨论】:

    猜你喜欢
    • 2021-07-10
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 2016-11-28
    • 2015-05-25
    • 2017-01-28
    • 2015-11-27
    相关资源
    最近更新 更多