Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何滚动滚动视图,使文本字段在SwiftUI中移动到键盘上方?_Ios_Swift_Swiftui_Swiftui List - Fatal编程技术网

Ios 如何滚动滚动视图,使文本字段在SwiftUI中移动到键盘上方?

Ios 如何滚动滚动视图,使文本字段在SwiftUI中移动到键盘上方?,ios,swift,swiftui,swiftui-list,Ios,Swift,Swiftui,Swiftui List,我已经设置了一个UI,其中滚动视图中有6个字段,如下所示: ... ScrollView { IndicatorTextField( index: 0, hint: "Full Name", icon: .imageUserBlue, activeFieldTag: self.$acti

我已经设置了一个UI,其中
滚动视图中有6个字段,如下所示:

...
         ScrollView {

                IndicatorTextField(
                    index: 0,
                    hint: "Full Name",
                    icon: .imageUserBlue,
                    activeFieldTag: self.$activeFieldTag,
                    type: .alphabet
                ).padding(.top, 48)

                IndicatorTextField(
                    index: 1,
                    hint: "Email Address",
                    icon: .imageEmail,
                    activeFieldTag: self.$activeFieldTag,
                    type: .emailAddress
                ).padding(.top, 8)

                IndicatorTextField(
                    index: 2,
                    hint: "Home Town",
                    icon: .imageLocation,
                    activeFieldTag: self.$activeFieldTag,
                    type: .alphabet
                ).padding(.top, 8)

                IndicatorTextField(
                    index: 3,
                    hint: "Password",
                    icon: .imageLock,
                    activeFieldTag: self.$activeFieldTag,
                    indicatorColor: .reddishPink
                ).padding(.top, 8)

                IndicatorTextField(
                    index: 4,
                    hint: "Date of Birth",
                    icon: .imageCalender,
                    activeFieldTag: self.$activeFieldTag,
                    type: .numbersAndPunctuation,
                    indicatorColor: .reddishPink
                ).padding(.top, 8)

                IndicatorTextField(
                    index: 5,
                    hint: "Gender",
                    icon: .imageUserRed,
                    activeFieldTag: self.$activeFieldTag,
                    indicatorColor: .reddishPink,
                    returnKey: .default
                ).padding(.top, 8)

                Spacer()
                    .frame(width: 0, height: -keyboardObserver.lastViewAdjustment)
            }
            .background(GeometryGetter(rect: $keyboardObserver.lastViewRect))
...
这是

当键盘出现时,我只需更改间隔符的高度,以滚动到最后一个字段

现在,我想自动滚动键盘上方的firstResponder


有人知道如何使用SwiftUI代码滚动
ScrollView
吗?

到目前为止,我还没有找到在SwiftUI中滚动
ScrollView
的方法,但我使用了一种变通方法,我告诉父滚动视图从
UITextField
的包装中滚动:

我发现这是一个比包装
UIScrollView
更简单的解决方案