macCatalyst/SwiftUI触摸栏 [英] macCatalyst/ SwiftUI Touch Bar

查看:205
本文介绍了macCatalyst/SwiftUI触摸栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SwiftUI编写的Catalyst-App中添加触摸栏支持?

how could I add Touch Bar Support in Catalyst- Apps written in SwiftUI?

例如,如果我想在视图中显示一个按钮:

For Example, if I want to display a Button in a View:

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack{
        #if targetEnvironment(macCatalyst)
            Text("macOS")
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .focusable()
            .touchBar {
                Button(action: {
                    print("tapped")
                }) {
                    Text("TestButton")
                }
            }
        #endif
        Text("iOS")
        }
    }
}

如果我在macOS应用程序中使用它,则可以工作,但是如果我在Catalyst中使用它并添加targetEnvironment,则会出现错误:

If I use it in a an macOS App it works but if I use it in Catalyst and add targetEnvironment it occurs the error:

'focusable(_:onFocusChange :)'在iOS中不可用,'touchBar(content :)'在iOS中不可用

'focusable(_:onFocusChange:)' is unavailable in iOS and 'touchBar(content:)' is unavailable in iOS

感谢您的帮助.

推荐答案

更改

#if targetEnvironment(macCatalyst)

#if os(macOS)

macCatalyst必须仍然在iOS Mac Catalyst应用程序的环境中,因此手动检查操作系统应该可靠.

macCatalyst must still be in the environment for iOS Mac Catalyst apps, so manually checking the OS should be reliable.

这篇关于macCatalyst/SwiftUI触摸栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆