Latest 1.0.1
Homepage https://github.com/iAmrMohamed/AMKeyboardFrameTracker
License MIT
Platforms ios 9.0
Frameworks UIKit
Authors

Simple iOS Keyboard frame tracker for custom interactive Keyboard dismissal

AMKeyboardFrameTracker

Features

  • [x] Very simple and easy to use API
  • [x] Provides both delegates and closure callbacks
  • [x] Can be used with any type of input views (UITextField, UITextView)
  • [x] Allows for interactive Keyboard dismissal in a UITabBarController with inputAccessoryView

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

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

pod 'AMKeyboardFrameTracker'

Requirements

  • Requires iOS 9.0+

Usage

let height = 60 // this should be your input view height
let keyboardFrameTrackerView = AMKeyboardFrameTrackerView.init(height: height)
inputTextView.inputAccessoryView = keyboardFrameTrackerView

Note

if your inputView height changes dynamically depending on the content inside it, then you will need keep the inputAccessoryView height in sync with your inputView height, to do that you need to override the viewDidLayoutSubviews in your ViewController and use the code below

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    self.keyboardFrameTrackerView.setHeight(self.inputContainerView.frame.height)
}

Closure Callbacks

keyboardFrameTrackerView.onKeyboardFrameDidChange = { [weak self] frame in
    guard let self = self else {return}
    print("Keyboard frame: ", frame)
}

Delegate Callbacks

keyboardFrameTrackerView.delegate = self
extension ExampleViewController: AMKeyboardFrameTrackerDelegate {
    func keyboardFrameDidChange(with frame: CGRect) {
        print("Keyboard frame: ", frame)
    }
}

UITabBarController Support

First you need to add your inputView to you ViewController view as a normal subview and then set all your constraints and layout, you will need to have a bottomConstraints from your inputView to ViewController view and use the code below

extension ExampleViewController: AMKeyboardFrameTrackerDelegate {
    func keyboardFrameDidChange(with frame: CGRect) {
        let tabBarHeight = self.tabBarController?.tabBar.frame.height ?? 0.0
        let bottomSapcing = self.view.frame.height - frame.origin.y - tabBarHeight - self.keyboardFrameTrackerView.frame.height

        self.inputViewBottomConstraint.constant = bottomSapcing > 0 ? bottomSapcing : 0
        self.view.layoutIfNeeded()
    }
}

Author

@iAmrMohamed

License

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

Latest podspec

{
    "name": "AMKeyboardFrameTracker",
    "version": "1.0.1",
    "summary": "Simple iOS Keyboard frame tracker for custom interactive Keyboard dismissal",
    "homepage": "https://github.com/iAmrMohamed/AMKeyboardFrameTracker",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "iAmrMohamed": "[email protected]"
    },
    "source": {
        "git": "https://github.com/iAmrMohamed/AMKeyboardFrameTracker.git",
        "tag": "1.0.1"
    },
    "social_media_url": "https://twitter.com/iAmrMohamed",
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.2",
    "source_files": "AMKeyboardFrameTracker/Classes/**/*",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This