Convert Figma logo to code with AI

danielamitay logoDAKeyboardControl

DAKeyboardControl adds keyboard awareness and scrolling dismissal (ala iMessages app) to any view with only 1 line of code.

1,575
214
1,575
40

Top Related Projects

MBProgressHUD + Customizations

⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features

A drop-in universal solution for moving text fields out of the way of the keyboard in iOS

Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.

Quick Overview

DAKeyboardControl is an iOS library that provides a simple and effective way to manage keyboard interactions in iOS applications. It allows developers to easily add keyboard awareness to their views, enabling smooth scrolling and automatic content adjustment when the keyboard appears or disappears.

Pros

  • Easy integration with existing UIScrollView and UITableView implementations
  • Smooth animation for keyboard appearance and disappearance
  • Customizable pan gesture for dismissing the keyboard
  • Lightweight and efficient implementation

Cons

  • Limited to iOS platform
  • May require additional configuration for complex view hierarchies
  • Not actively maintained (last update was several years ago)
  • Might not be fully compatible with the latest iOS versions

Code Examples

  1. Adding keyboard awareness to a scroll view:
scrollView.addKeyboardControl()
  1. Customizing the pan gesture for dismissing the keyboard:
scrollView.addKeyboardControl(withPanGestureRecognizer: true)
  1. Handling keyboard events manually:
scrollView.addKeyboardControl { [weak self] (state, height) in
    switch state {
    case .active:
        self?.adjustContentForKeyboard(height: height)
    case .hidden:
        self?.resetContent()
    }
}

Getting Started

To use DAKeyboardControl in your project:

  1. Add the library to your project (via CocoaPods, Carthage, or manually)
  2. Import the library in your view controller:
import DAKeyboardControl
  1. Add keyboard control to your scroll view or table view:
override func viewDidLoad() {
    super.viewDidLoad()
    scrollView.addKeyboardControl()
}
  1. Optionally, customize the behavior:
scrollView.addKeyboardControl(withPanGestureRecognizer: true) { [weak self] (state, height) in
    // Handle keyboard events
}

Competitor Comparisons

MBProgressHUD + Customizations

Pros of MBProgressHUD

  • Provides a comprehensive set of progress indicators and HUD (Heads-Up Display) elements
  • Highly customizable with various styles, animations, and modes
  • Widely adopted and well-maintained, with extensive documentation

Cons of MBProgressHUD

  • Focused solely on progress indicators, lacking keyboard management features
  • May require additional setup for complex UI interactions
  • Potential performance impact when used excessively

Code Comparison

MBProgressHUD:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.label.text = @"Loading...";
[hud showAnimated:YES];

DAKeyboardControl:

[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
    // Adjust UI elements based on keyboard frame
}];

Summary

MBProgressHUD excels in providing progress indicators and HUD elements, offering extensive customization options. It's widely adopted and well-maintained. However, it lacks keyboard management features, which is the primary focus of DAKeyboardControl. MBProgressHUD may require additional setup for complex UI interactions and could impact performance if overused. DAKeyboardControl, on the other hand, specializes in keyboard management but doesn't offer progress indication functionality. The choice between these libraries depends on the specific needs of your project, whether it's progress indication or keyboard handling.

⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features

Pros of SlackTextViewController

  • More comprehensive solution, offering a full-featured text input controller
  • Includes auto-growing text view and customizable input accessory view
  • Provides built-in support for mentions, hashtags, and other rich text features

Cons of SlackTextViewController

  • Larger codebase, potentially more complex to integrate and customize
  • May include features not needed for simpler applications
  • Requires more setup and configuration compared to DAKeyboardControl

Code Comparison

DAKeyboardControl:

[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
    // Update UI based on keyboard frame
}];

SlackTextViewController:

SLKTextViewController *textViewController = [SLKTextViewController new];
textViewController.textView.placeholder = @"Message";
textViewController.bounces = YES;
textViewController.keyboardPanningEnabled = YES;

Summary

SlackTextViewController offers a more feature-rich solution for text input handling, including auto-growing text views and support for rich text features. However, it comes with a larger codebase and potentially more complex integration. DAKeyboardControl provides a simpler, focused solution for keyboard management, which may be sufficient for many applications. The choice between the two depends on the specific requirements of your project and the level of customization needed.

A drop-in universal solution for moving text fields out of the way of the keyboard in iOS

Pros of TPKeyboardAvoiding

  • Simpler implementation with less code, making it easier to integrate and maintain
  • Works automatically with UIScrollView and its subclasses without additional setup
  • Supports both portrait and landscape orientations out of the box

Cons of TPKeyboardAvoiding

  • Less customizable than DAKeyboardControl
  • Doesn't provide advanced features like pan gesture recognition for keyboard dismissal
  • May not work as well with complex view hierarchies or custom layouts

Code Comparison

TPKeyboardAvoiding:

[self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width, 700)];
[TPKeyboardAvoiding willMoveToSuperview:self.scrollView];

DAKeyboardControl:

[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
    // Custom logic here
}];

TPKeyboardAvoiding offers a more straightforward approach, automatically handling keyboard avoidance for scroll views. DAKeyboardControl provides more flexibility and control over keyboard interactions, allowing for custom behaviors and animations.

Both libraries serve their purposes well, with TPKeyboardAvoiding being ideal for simpler implementations and DAKeyboardControl offering more advanced features for complex user interfaces.

Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.

Pros of IQKeyboardManager

  • More comprehensive solution with automatic handling of keyboard appearance and dismissal
  • Supports multiple input views and scrollviews simultaneously
  • Actively maintained with frequent updates and bug fixes

Cons of IQKeyboardManager

  • Larger codebase and potentially higher overhead
  • May require more configuration for complex scenarios
  • Could interfere with custom keyboard handling implementations

Code Comparison

DAKeyboardControl:

[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
    // Handle keyboard frame changes
}];

IQKeyboardManager:

IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = false
IQKeyboardManager.shared.shouldResignOnTouchOutside = true

Summary

IQKeyboardManager offers a more feature-rich and automated approach to keyboard management, while DAKeyboardControl provides a simpler, more lightweight solution. IQKeyboardManager is better suited for complex applications with multiple input fields, whereas DAKeyboardControl may be preferable for projects requiring more manual control over keyboard interactions. The choice between the two depends on the specific needs of the project and the desired level of customization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

DAKeyboardControl

DAKeyboardControl allows you to easily add keyboard awareness and scrolling dismissal (a receding keyboard ala iMessages app) to any UIView,UIScrollView or UITableView with only 1 line of code. DAKeyboardControl automatically extends UIView and provides a block callback with the keyboard's current frame.

DAKeyboardControl now fully supports orientation changes, iPhone & iPad, and is even aware of keyboard undocking or splitting on the iPad.

No hacks, fully App Store safe.

Screenshot

Video demonstration on YouTube

Installation

  • Copy over the DAKeyboardControl folder to your project folder.
  • #import "DAKeyboardControl.h"

Usage

Example project included (DAKeyboardControlExample)

Adding pan-to-dismiss (functionality introduced in iMessages)

[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
        // Move interface objects accordingly
		// Animation block is handled for you
    }];
	// Make sure to call [self.view removeKeyboardControl] before the view is released.
	// (It's the balancing call)

Adding keyboard awareness (appearance and disappearance only)

[self.view addKeyboardNonpanningWithActionHandler:^(CGRect keyboardFrameInView) {
        // Move interface objects accordingly
		// Animation block is handled for you
    }];
	// Make sure to call [self.view removeKeyboardControl] before the view is released.
	// (It's the balancing call)

Supporting an above-keyboard input view

The keyboardTriggerOffset property allows you to choose at what point the user's finger "engages" the keyboard.

self.view.keyboardTriggerOffset = 44.0f;	// Input view frame height

[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
        // Move input view accordingly
		// Animation block is handled for you
    }];
	// Make sure to call [self.view removeKeyboardControl] before the view is released.
	// (It's the balancing call)

Dismissing the keyboard (convenience method)

[self.view hideKeyboard];

Remove the NSNotification observer at the end of a VC's life (convenience method)

[self.view removeKeyboardControl];

Notes

Tested in App Store!

All code is iOS 5.0+ safe and well documented, and is already in production apps on the App Store.

Using with a UITextView

Make sure to call addKeyboardPanningWithActionHandler: on the UITextView itself if you wish for it to allow panning inside itself.

Keyboard Delay On First Appearance

Standard iOS issue. Use Brandon William's UIResponder category to cache the keyboard before first use.

Automatic Reference Counting (ARC) support

DAKeyboardControl was made with ARC enabled by default.

Contact

If you use/enjoy DAKeyboardControl, let me know!

License

MIT License

Copyright (c) 2012 Daniel Amitay (http://danielamitay.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.