FollowKeyboard icon indicating copy to clipboard operation
FollowKeyboard copied to clipboard

Keep your views visible when keyboard is being shown

FollowKeyboard

Keep your views visible when keyboard is being shown.

Screens

screen 1

Requirements

  • iOS 8.0 +
  • Swift 5.0 +

Install

Carthage

Add following to your Cartfile and run Carthage update.

github "DanisFabric/FollowKeyboard"

Manual

add FollowKeyboard.swift to your project.

Usage

Layout using frame

    let fk = FollowKeyboard()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        fk.followKeyboard(withAnimations: { [unowned self] (keyboardFrame, duration, type) in
            switch type {
            case .show:
                self.bottomBar.frame = self.bottomBar.frame.offsetBy(dx: 0, dy: -keyboardFrame.height)
            case .hide:
                self.bottomBar.frame = self.bottomBar.frame.offsetBy(dx: 0, dy: keyboardFrame.height)
            }
        }, completionBlock: nil)
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        
        fk.unfollowKeyboard()
    }
    
       

Layout using Autolayout

    let fk = FollowKeyboard()

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        fk.followKeyboard(withAnimations: { (keyboardFrame, duration, type) in
            switch type {
            case .show:
                self.barBottomConstaint.constant += keyboardFrame.height
                self.view.layoutIfNeeded()
            case .hide:
                self.barBottomConstaint.constant -= keyboardFrame.height
                self.view.layoutIfNeeded()
            }
        }, completionBlock: nil)
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        
        fk.unfollowKeyboard()
    }

You'd better add the code to viewWillAppear: and viewDidDisappear

Contact

contact me: [email protected]