Swift iOS How to update your view when keyboard appears
Vložit
- čas přidán 13. 07. 2024
- In this video I show you two ways to update your views based on the appearance of the UITextField keyboard.
0:00 Intro
1:36 How to detect the presence of the keyboard
2:00 How to shift the entire view up
3:22 How to adjust the view dynamically
6:18 How to determine which element was tapped
8:00 Converting coordinate system
10:18 Apple's new keyboard layout guide
13:10 Wrap up
🤖 Source code
github.com/jrasmusson/ios-pro...
Articles
developer.apple.com/design/hu...
developer.apple.com/design/hu...
developer.apple.com/documenta...
developer.apple.com/documenta...
🕹 Level up further with these awesome courses
Professional iOS Development
www.udemy.com/course/the-swif...
Data Structures & Algorithms
www.udemy.com/course/the-swif...
Level Up in AutoLayout
www.udemy.com/course/level-up...
Level Up in Swift
www.udemy.com/course/level-up... - Věda a technologie
Makes great sense and thanks for providing, I really am mind blown that it has to be this complex though... Best explanation I've found though
great tutorial with detailed explanation, thanks a lot, it was very useful for me
Thanks for doing this! 💯
Great content and explanations! Thank you so much!
Most welcome teaberry. Good to see you.
As always brilliant explanation!!
Cheers Roman. Thank you so much.
Practical tip. Thank you Jonathan
Very welcome. Good to see you Avocado.
Thanks Jonathan 👏
Nicely done ✅
Thanks!
You are perfect
You are genius 👍🏻
Thank you so much Roman. Glad you enjoyed the video.
Hey man. How are you? So, I really like your approach man. Do you give private lessons? Or like a mentoring? Take care man. Great videos always.
No private lessons at the moment Thiago. But I try to mentor those my videos and courses. Much cheaper than hiring me privately. Feel free to ask me any question though. Cheers - Jonathan
Hello! Thank you for the tutorial. I wanted to ask about the state when textFieldBottomY does not overlapped by keyboardTopY but at the same time keyboard is overlapping the UIButton that we need to press when text was entered. Would it also work? Thanks.
❤❤
Thank you so much Jonathan! This is the only tutorial that's gone the programmatic way, just what I needed 🫡
03:10 scroll up textfield
Day Jonathon, great explanation. I see that the comments are a year old and the IOS changes regularly. When I type in your nuanced boolean solution for checking whether to raise the view or not - I get an error from this line of code - let currentTextField = UIResponder.currentFirst() as? UITextField else {return}
The error message is - Type 'UIResponder' has no member 'currentFirst'. Can you please help me on this? Cheers n beers
This seems to work only if you select the textbox once, if you dismiss the keyboard and then select the text field again it will change the scroll height. Any ideas?
Yes. As mentioned in the video, if you want to make method #1 work you'll need to create a Bool and track whether the textbox has been tapped and only adjust if it hasn't. I just showed people that for demo purposes. If you go with the more advanced solution #2 everything works fine.
@@swiftarcade7632 Sorry I should've clarified, I am having this issue with method #2 - so that when you select a textbox the second time and then dismiss the keyboard there is additional spacing that gets added to the scrollview.
@@SamacInnes Ah. Sorry. I believe you, but I can't seem to replicate the problem. I did run into an issue with there being extra space when applying this technique to a SwiftUI app. But not UIKit. If you download. My suggestion would be to double check the offset values, see if there is anything else affecting the layout in the UI, and maybe start with a fresh project. My example was pretty base and simple. Good luck!
@@swiftarcade7632 Okay thank you for your suggestion! I appreciate the quick reply
@@SamacInnes No problem!
Can I ask you why? The UI is so simple but you made so much code. Is that the advantage of creating UI programmatically? If you use storyboard, you will reduce the code by 80%. What is the purpose to have more code?
Hi Haha - great question. Yes the UI is simple. Yes a nib would have saved some code. Just copied this in quickly for demo purposes. If you Google storyboards vs programmatic you'll find some good points for both. Cheers.