How to use @FocusState in SwiftUI Tutorial (New in iOS 15)

preview_player
Показать описание
In this lesson we will be covering how we can use the @FocusState property wrapper to create focus on certain views in our apps. This is great if you want to take care of events such as dismissing the keyboard.

Рекомендации по теме
Комментарии
Автор

Well done sir! Succint and to the point. Looks like a very useful technique!

KimbrellBrad
Автор

Hey! I have an issue with this solution on iOS 16.2. On submitting the first field the keyboard bounces slightly down and back up. It is really annoying and I didn’t found anything helpful yet. Do you know something about this problem? 😢

PenekNeudachi
Автор

Thank you very much, very helpful ;-) Do you have any experience with SwiftUI focus matters under watchOS?

If you have a ScrollView with several buttons in it (yes, a ScrollView and no ListView because I want to scroll it programmatically), this ScrollView would have automatically the focus and the Digital Crown scrolls it. Perfect, this is what I want.

But if I add another element that should receive the focus, e. g. a button (within this ScrollView), on which I want to change the Text Label displaying a value, this button would keep the focus, not “giving it back” to the ScrollView itself.

At first, the whole ScrollView should be scrolled by the Digital Crown, the focus being shifted to the button that now displays changing values (changed by using the Digital Crown) — and eventually, I want to dismiss the focus from the button to make the whole ScrollView scroll again by the Digital Crown action.

Any ideas would be appreciated ;-)

I mean, ScrollView seems to be special under watchOS, since it seems to have the focus automatically, without my intervention…

anotherguycalledsmith
Автор

In a macOS app, how do you handle tab keys to change focus?

LukePighetti
join shbcf.ru