如何使 macOS 上的视图可聚焦。我尝试过如下所示,但从未触发该操作。我知道对于 NSView 你必须实现acceptsFirstResponder返回 true 但在 SwiftUI 中找不到类似的。
这仍然是与 Beta 相关的错误还是 macOS 的缺失功能?
struct FocusableView: View {
var body: some View {
Group {
Text("Hello World!")
.padding(20)
.background(Color.blue.cornerRadius(8))
.focusable(true) { isFocused in
print("Focused", isFocused)
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试找到在 macOS 上将 NSMenuItem 与 SwiftUI onCommand 连接的最佳解决方案。
目前我正在做以下事情:
@IBAction func changeColor(_ sender: Any) {
print("Dummy Function")
}
Run Code Online (Sandbox Code Playgroud)
使用 Main.storyboard 中的 First Responder 函数创建并连接一个 NSMenuItem。
将所需的代码添加到我的 SwiftUI 视图中
struct TestView: View {
let changeColor = #selector(AppDelegate.changeColor(_:))
var body: some View {
VStack {
TextField("Text", text: .constant(""))
Text("Hello World!")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onCommand(changeColor) {
print("Change Color Action")
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果 TextField 在我看到打印“更改颜色操作”之前是第一响应者。如果 TextField 之前不是第一响应者,则视图不会成为第一响应者。也许这目前是 Catalina Beta (19A558d) 中的一个错误,因为我也无法专注于工作。
我需要将侧边栏删除到我的 woocommerce 商店中。我在选项主题和每个类别中尝试过后端,但没有结果。
我也试过:
1.file wp-template-hooks.php 已删除--> do_action(..
2.file archive-product.php 删除--> do_action(..
在主题目录中插入文件 function.php,在 woocommerce 目录中插入 function.php remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
到数据库中有 2 个表,其中 2 个字段被序列化,但这是一个风险改变。
无情的。
我完成了这些想法。侧边栏的可见性在哪里保存到数据库中?还是变量?
你能帮助我吗?
谢谢艾尔