如何使macOS上的View聚焦。我尝试了以下操作,但从未触发该操作。我知道对于NSView,您必须实现acceptsFirstResponder
以返回true,但在SwiftUI中找不到类似的代码。
这仍然是与Beta相关的bug或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)
}
}
}
}
最佳答案
关于SwiftUI-使 View 可聚焦并在macOS上触发操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58049130/