KeyboardManager

@available(iOSApplicationExtension, unavailable)
open class KeyboardManager : NSObject, UIGestureRecognizerDelegate

An object that observes keyboard notifications such that event callbacks can be set for each notification

Properties [Public]

  • A weak reference to a view bounded to the top of the keyboard to act as an InputAccessoryView but kept within the bounds of the UIViewControllers view

    Declaration

    Swift

    open weak var inputAccessoryView: UIView?
  • A flag that indicates if a portion of the keyboard is visible on the screen

    Declaration

    Swift

    private(set) public var isKeyboardHidden: Bool { get }
  • A flag that indicates if the additional bottom space should be applied to the interactive dismissal of the keyboard

    Declaration

    Swift

    public var shouldApplyAdditionBottomSpaceToInteractiveDismissal: Bool

Initialization

  • Creates a KeyboardManager object an binds the view as fake InputAccessoryView

    Declaration

    Swift

    public convenience init(inputAccessoryView: UIView)

    Parameters

    inputAccessoryView

    The view to bind to the top of the keyboard but within its superview

  • Creates a KeyboardManager object that observes the state of the keyboard

    Declaration

    Swift

    public override init()
  • Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

Mutate Callback Dictionary

  • Sets the EventCallback for a KeyboardEvent

    Declaration

    Swift

    @discardableResult
    open func on(event: KeyboardEvent, do callback: EventCallback?) -> Self

    Parameters

    event

    KeyboardEvent

    callback

    EventCallback

    Return Value

    Self

  • Constrains the inputAccessoryView to the bottom of its superview and sets the .willChangeFrame and .willHide event callbacks such that it mimics an InputAccessoryView that is bound to the top of the keyboard

    Declaration

    Swift

    @discardableResult
    open func bind(inputAccessoryView: UIView, withAdditionalBottomSpace additionalBottomSpace: (() -> CGFloat)? = .none) -> Self

    Parameters

    inputAccessoryView

    The view to bind to the top of the keyboard but within its superview

    Return Value

    Self

  • Adds a UIPanGestureRecognizer to the scrollView to enable interactive dismissal`

    Declaration

    Swift

    @discardableResult
    open func bind(to scrollView: UIScrollView) -> Self

    Parameters

    scrollView

    UIScrollView

    Return Value

    Self

Keyboard Notifications

  • An observer method called last in the lifecycle of a keyboard becoming visible

    Declaration

    Swift

    @objc
    open func keyboardDidShow(notification: NSNotification)

    Parameters

    notification

    NSNotification

  • An observer method called last in the lifecycle of a keyboard becoming hidden

    Declaration

    Swift

    @objc
    open func keyboardDidHide(notification: NSNotification)

    Parameters

    notification

    NSNotification

  • An observer method called third in the lifecycle of a keyboard becoming visible/hidden

    Declaration

    Swift

    @objc
    open func keyboardDidChangeFrame(notification: NSNotification)

    Parameters

    notification

    NSNotification

  • An observer method called first in the lifecycle of a keyboard becoming visible/hidden

    Declaration

    Swift

    @objc
    open func keyboardWillChangeFrame(notification: NSNotification)

    Parameters

    notification

    NSNotification

  • An observer method called second in the lifecycle of a keyboard becoming visible

    Declaration

    Swift

    @objc
    open func keyboardWillShow(notification: NSNotification)

    Parameters

    notification

    NSNotification

  • An observer method called second in the lifecycle of a keyboard becoming hidden

    Declaration

    Swift

    @objc
    open func keyboardWillHide(notification: NSNotification)

    Parameters

    notification

    NSNotification

UIGestureRecognizerDelegate

  • Starts with the cached KeyboardNotification and calculates a new endFrame based on the UIPanGestureRecognizer then calls the .willChangeFrame EventCallback action

    Declaration

    Swift

    @objc
    open func handlePanGestureRecognizer(recognizer: UIPanGestureRecognizer)

    Parameters

    recognizer

    UIPanGestureRecognizer

  • Only receive a UITouch event when the scrollView‘s keyboard dismiss mode is interactive

    Declaration

    Swift

    open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool
  • Only recognice simultaneous gestures when its the panGesture

    Declaration

    Swift

    open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool