KeyboardLayoutGuide in iOS15*

Pawan Manjani
2 min readSep 24, 2023

--

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.

Source https://gifer.com

What if I want to use in storyboard?

  1. Select your main view and go to size inspector and then select Keyboard checkbox
  2. Give your view’s bottom constraint to KeyboardLayoutGuide’s top

Just it!

For more visit: https://ioslifee.blogspot.com

Thanks for reading, Happy Coding 💻

--

--