4

I am working on a feature for my app which will allow user to dictate text which will appear in a textField. For that I created a scrollView with only a textField which contents are automatically updating as user is dictating. However I came across a problem regarding the autoscrolling of the scrollView. Because the textFields height is growing with new text coming in at some point it is as height as the scroll view which means that at this point textFields height will continue to grow but the user will not see any new text.

How do I programmatically make sure that if the textfield outgrows in height the scrollView, the scrollview will scroll down to show new text?

I already tried to use the ScrollViewReader, ScrollViewProxy and the .onChange closure but it doesn't seem to have any affect.

ScrollViewReader{proxy in
                        ScrollView(.vertical, showsIndicators: false) {
                            Text(newMessageText)
                            .frame(width: 230, alignment: .center)
                            .font(.system(size: 46))
                            .foregroundColor(.black)
                            .multilineTextAlignment(.leading)
                            .lineLimit(nil)
                            .padding()
                            .id(textViewId)
                        }
                        .onChange(of: newMessageText) { newValue in
                            proxy.scrollTo(textViewId, anchor: .bottom)
                        }
                        }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.