KeyboardLayoutGuide in iOS15*
Apple says A layout guide that tracks the keyboard’s position in your app’s layout.
In simple words KeyboardLayoutGuide help us to setup view frame according to the keyboard position when keyboard appears in the screen.
Before iOS15 we use to import IQKeyboardManager in our project to adjust our view when keyboard appears in our application’s view and it’s very wonderful library to use or we used to manually set up a NotificationCenter to adjust our view when keyboard appears. But now we have KeyboardLayoutGuide to help us here.
Let me show you an example
yourView.bottomAnchor.constraint(equalTo: self.view.keyboardLayoutGuide.bottomAnchor).isActive = true
In above code we given bottomAnchor of our view constraint to keyboardLayoutGuide’s bottomAnchor and just it.
What if I want to use in storyboard?
- Select your main view and go to size inspector and then select Keyboard checkbox
- Give your view’s bottom constraint to KeyboardLayoutGuide’s top
Just it!
For more visit: https://ioslifee.blogspot.com
Thanks for reading, Happy Coding 💻