小编Hey*_*man的帖子

如何在 swiftui 中使用 .quickLookPreview 修饰符

我正在尝试使用.quickLookPreviewiOS 14、macOS 11 macCatalyst 14 中引入的视图修改器,但Value of type 'some View' has no member 'quickLookPreview'每次尝试在 macOS 或 mac Catalyst 目标上使用该修改器时都会收到此错误。在 iOS 上,这工作得很好。在 Mac 上呈现此修改器的正确方法是什么?

import SwiftUI
import QuickLook


struct ContentView: View {

@State var documentUrl: URL?

var body: some View {
    NavigationView {

    ZStack {
        
        Button("Press Me", action: {
            documentUrl = URL(fileURLWithPath: "somelocalfileURLPath")
        })
        
        
       
    }
    .navigationTitle("Open File")
    .quickLookPreview($documentUrl)
        
    }
    
}

}
Run Code Online (Sandbox Code Playgroud)

Xcode 13.1 MacOS 12.1

macos quicklook swiftui mac-catalyst viewmodifier

6
推荐指数
1
解决办法
1844
查看次数

SwiftUI 游戏中心身份验证不提示用户登录

我有以下代码可以在我的 SwiftUI 应用程序中对 Game Center 中的本地玩家进行身份验证。如果玩家尚未登录,我希望 Game Center 提示用户登录,但这不会发生。

class AppSettings: UINavigationController {
    func authenticateUser() {
        let localPlayer = GKLocalPlayer.local
        localPlayer.authenticateHandler = { vc, error in
            guard error == nil else {
                print(error?.localizedDescription ?? "")
                return
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?我还阅读了关于在我班级的某处使用 UIViewControllerRepresentable 将 UIKit 的 ViewController 集成到 SwiftUI 中的内容,但我不明白如何使用它。有人可以帮我吗?

gamekit game-center swift swiftui uiviewcontrollerrepresentable

5
推荐指数
1
解决办法
355
查看次数

是否可以在 SwiftUI iOS 应用程序中组合 WindowGroup 和 DocumentGroup?

我正在开发一个 SwiftUI iOS 应用程序,最初是从 A WindowGroup 开始的。在另一个视图中,我决定需要将该视图呈现为 DocumentGroup 场景,以利用它附带的所有功能。我不希望应用程序的入口点是 DocumentGroup 场景。我只是希望我的应用程序的入口点是 WindowGroup 场景,然后在 WindowGroup 场景的另一个视图中,我想调用 DocumentGroup 场景来打开,就好像该应用程序是基于文档的应用程序一样。任何帮助都感激不尽。谢谢

ios swift swiftui documentgroup swiftui-windowgroup

5
推荐指数
1
解决办法
828
查看次数