MetovaBase 2.0.0

MetovaBase 2.0.0

LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2018
SPMSupports SPM

Maintained by Nick Griffith, Logan Gauthier, Metova, Inc., Chris Martin, Beverly Massengill, Chris Dillard.

  • By
  • Nick Griffith and Logan Gauthier


Build Status CocoaPods Compatible Documentation Coverage Status Platform Twitter


  • iOS 8.0
  • Swift 4.2


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

pod 'MetovaBase'


MetovaBase offers useful UIKit subclasses that implement commonly used utilities.


The BaseViewController class extends from UIViewController and adds a common utility that we have found ourselves adding in most, if not all, of our view controller classes. It does some additional setup in viewDidLoad to provide your view controller with keyboard notifications. If overriding, be sure to call super.viewDidLoad in your subclass.

Example usage:

import MetovaBase

class MyViewController: BaseViewController {

    override func viewDidLoad() {
    	// this call registers your VC for keyboard notifications
    	// my custom setup here

Additionally, BaseViewController unregisters your view controller from receiving keyboard notifications in its deinit() method.


This protocol contains a collection of methods which BaseViewController subclasses (or extensions) can implement in order to hear about keyboard notifications. As already stated, you do not need to register or unregister for these notifications in your subclass or extension--you simply need to implement these methods.


These methods are called when the appropriate keyboard notification is fired.

@objc optional func keyboardWillShow(notification: Notification)

@objc optional func keyboardDidShow(notification: Notification)

@objc optional func keyboardWillChangeFrame(notification: Notification)

@objc optional func keyboardDidChangeFrame(notification: Notification)

@objc optional func keyboardWillHide(notification: Notification)

@objc optional func keyboardDidHide(notification: Notification)


BaseViewControllerConvenience provides a convenience method to dismiss the keyboard. It assumes the first responder is a descendant of your view controller's view. Since it is an extension of BaseViewController, you can call the method anywhere in your BaseViewController subclass like so:


Or as a selector like so:

dismissGestureRecognizer.addTarget(self, action: #selector(dismissKeyboard))


BaseViewControllerFrames provides some additional helper methods for handling the keyboard in your view controller. Again, this extends BaseViewController, so these methods are available anywhere in your BaseViewController subclass.


public func framesForKeyboard(notification: Notification) -> (fromFrame: CGRect, toFrame: CGRect) 

This method returns the starting and ending frames of the keyboard. It parses the frame information from the notification that is passed in. If there is no frame information in the notification object, is returned.

public func adjustContentInset(scrollview scrollView: UIScrollView, forKeyboardWillChangeFrameNotification notification: Notification)

As can be surmised by the name, this method adjusts the scrollview's inset based on the keyboard frame. This is helpful for views where the keyboard may cover up the first responder.

Example Usage

import MetovaBase

class MyViewController: BaseViewController, KeyboardNotificationDelegate {

	@IBOutlet myScrollView: UIScrollView!

	@objc func keyboardDidChangeFrame(notification: Notification) {
		let frames = framesForKeyboard(notification: notification)
		let fromFrame = frames.fromFrame
		let toFrame = frames.toFrame
		// do whatever you need to with the 'fromFrame' and 'toFrame'

	@objc func keyboardWillChangeFrame(notification: Notification) {

		adjustContentInset(scrollView: myScrollView, forKeyboardWillChangeNotification: notification)


MetovaBase is owned and maintained by Metova Inc.


If you would like to contribute to Metova Test Kit, see our CONTRIBUTING guidelines.

Metova Test Kit banner image and other assets provided by Christi Johnson.


MetovaBase is available under the MIT license. See the LICENSE file for more info.