Xcode 如何在SwiftUI中为WatchOS6获取scribble输入
我正试图这样做,当用户点击按钮,里面有评论,它会弹出一个涂鸦用户输入和听写。我考虑了一些其他的解决方案,但我没能让它们中的任何一个起作用。我认为这可能是因为它们都是watchOS3中实现的建议。我也查看了苹果的文档,发现了这个,但是我没能让它工作。下面是我的完整代码Xcode 如何在SwiftUI中为WatchOS6获取scribble输入,xcode,button,user-input,swiftui,watchos-6,Xcode,Button,User Input,Swiftui,Watchos 6,我正试图这样做,当用户点击按钮,里面有评论,它会弹出一个涂鸦用户输入和听写。我考虑了一些其他的解决方案,但我没能让它们中的任何一个起作用。我认为这可能是因为它们都是watchOS3中实现的建议。我也查看了苹果的文档,发现了这个,但是我没能让它工作。下面是我的完整代码 导入快捷界面 进口基金会 结构ContentView:View{ @状态变量计数器值=[0,0,0,-1,-1,-1,-1,-1,-1,-1] @状态变量计数器名称=[“上拉”、“俯卧撑”、“仰卧起坐”、“俯卧起坐”、“仰卧起坐”、
导入快捷界面
进口基金会
结构ContentView:View{
@状态变量计数器值=[0,0,0,-1,-1,-1,-1,-1,-1,-1]
@状态变量计数器名称=[“上拉”、“俯卧撑”、“仰卧起坐”、“俯卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“仰卧起坐”、“, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
@状态变量计数器=3;
var body:一些观点{
滚动视图{
VStack{
ForEach(counterValues.index){index in
if(自身计数器值[索引]>=0){
文本(\(self.counterNames[index]))
按钮(操作:{
self.counterValues[index]+=1
}) {
文本(\(self.counterValues[index]))
.font(.title)
.multilitextalignment(.center)
}
}
}
按钮(操作:{
//在此处添加用户输入
}) {
图像(系统名称:“plus”)
.font(.largeTitle)
.foregroundColor(.绿色)
}
.转弯半径(40)
.shadow(颜色:灰色,半径:/*@START\u MENU\u TOKEN@*/10/*@END\u MENU\u TOKEN@*/)
.填充(20)
}
}
}
}
结构内容视图\u预览:PreviewProvider{
静态var预览:一些视图{
ContentView()
}
}
这是一个特定的按钮,当点击它时,我想让它允许用户输入,然后将输入存储在一个变量中
Button(action: {
//Add user input here
}) {
Image(systemName: "plus")
.font(.largeTitle)
.foregroundColor(.green)
}
.cornerRadius(40)
.shadow(color: .gray, radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/ )
.padding(20)
您可以使用textfield尝试以下代码
struct ContentView: View {
@State
var counterValues = [0,0,0, -1, -1, -1, -1, -1, -1, -1 ]
@State var counterNames = ["Pullups", "Pushups", "Situps", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
@State var counters = 3;
@State var textInput = "";
@State var showInput = false;
var body: some View {
ScrollView {
VStack {
ForEach( counterValues.indices ) { index in
if (self.counterValues[index]>=0) {
Text("\(self.counterNames[index])")
Button(action: {
self.counterValues[index] += 1
}) {
Text("\(self.counterValues[index])")
.font(.title)
.multilineTextAlignment(.center)
}
}
}
Button(action: {
//Add user input here
self.showInput.toggle()
}) {
Image(systemName: "plus")
.font(.largeTitle)
.foregroundColor(.green)
}
.cornerRadius(40)
.shadow(color: .gray, radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/ )
.padding(20)
if self.showInput{
TextField.init("input", text: $textInput)}
}
}
}
}
您可以使用textfield尝试以下代码
struct ContentView: View {
@State
var counterValues = [0,0,0, -1, -1, -1, -1, -1, -1, -1 ]
@State var counterNames = ["Pullups", "Pushups", "Situps", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
@State var counters = 3;
@State var textInput = "";
@State var showInput = false;
var body: some View {
ScrollView {
VStack {
ForEach( counterValues.indices ) { index in
if (self.counterValues[index]>=0) {
Text("\(self.counterNames[index])")
Button(action: {
self.counterValues[index] += 1
}) {
Text("\(self.counterValues[index])")
.font(.title)
.multilineTextAlignment(.center)
}
}
}
Button(action: {
//Add user input here
self.showInput.toggle()
}) {
Image(systemName: "plus")
.font(.largeTitle)
.foregroundColor(.green)
}
.cornerRadius(40)
.shadow(color: .gray, radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/ )
.padding(20)
if self.showInput{
TextField.init("input", text: $textInput)}
}
}
}
}
你试过使用文本字段吗?安德鲁是对的。你可以用一个文本字段。是的,一个文本字段确实有效,所以我使用了E.Coms发布的内容,它在何时切换它起作用。谢谢你试过使用文本字段吗?安德鲁是对的。你可以用一个文本字段。是的,一个文本字段确实有效,所以我使用了E.Coms发布的内容,它在何时切换它起作用。谢谢