Nathan Fiscaletti

If you can make sense of bad documentation effectively, you're already better than 90% of engineers.

Home

Locking a view to the top of the keyboard in iOS

Published Mar 21, 2019

Recently I’ve come across the issue where I need to lock a view to the top of the keyboard when it is displayed in an iOS application.

This was doable with a small extension to UIView, how ever it didn’t offer a lot in the way of customization without adding a decent chunk of code.

So, I set to work on KeyboardLock, a simple module for iOS apps that will do most of the work for you.

Installation

KeyboardLock is available through CocoaPods. To install it, simply add the following line to your Podfile:

$ pod 'KeyboardLock'

Usage

Implementing a keyboard lock is as simple as the following

KeyboardLock(
    withView: containerView,
    andLockType: .BottomConstraint
).lock()

See the GitHub Repository