Skip to content

DanisFabric/FollowKeyboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]

About

Keep your views visible when keyboard is being shown

Resources

Stars

Watchers

Forks

Packages

No packages published