Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
douglashill/KeyboardKit
KeyboardKit
KeyboardKit makes it easy to add hardware keyboard control to iOS and Mac Catalyst apps.
Keyboard control is a standard expectation of Mac apps. It’s important on iOS too because a hardware keyboard improves speed and ergonomics, which makes an iPad an even more powerful productivity machine.
Apps created with AppKit tend to have better support for keyboard control compared to UIKit-based apps. I believe the principal reason for this is that most AppKit components respond to key input out of the box, while most UIKit components do not. KeyboardKit aims to narrow this gap by providing subclasses of UIKit components that respond to key commands.
Features
- Keyboard cell selection
- Keyboard navigation
- Keyboard scrolling and zooming
- Key equivalents for buttons
- Advanced text navigation
- Keyboard window management
- Keyboard date picker
- 39 localisations
- Clean implementation
Requirements
KeyboardKit supports iOS 12.0 onwards on iPad, iPhone and Mac Catalyst (both scaled and optimised). tvOS is not supported. The latest Xcode 12.x is required.
Both Swift and Objective-C apps are supported. Since KeyboardKit is implemented in Swift, it’s not possible subclass KeyboardKit classes from Objective-C. However all other features of KeyboardKit are available to Objective-C apps.
Installation
Direct
- Clone this repository.
- Drag
KeyboardKit.xcodeproj
into your Xcode project. - Add the KeyboardKit target as a dependency of your target.
- Add
KeyboardKit.framework
as an embedded framework.
Swift Package Manager
Add KeyboardKit to an existing Xcode project as a package dependency:
- From the File menu, select Swift Packages › Add Package Dependency…
- Enter "https://github.com/douglashill/KeyboardKit" into the package repository URL text field.
This Swift package contains localised resources, so Swift 5.3 (Xcode 12) or later is required.
Swift Package Manager requires the Swift and Objective-C sources to be separated into modules. The KeyboardKitObjC
module is used internally by KeyboardKit and does not need to be imported explicitly by your app.
CocoaPods
-
Add the following to your
Podfile
:pod 'Keyboard-Kit'
-
Run the following command:
pod install
Please open a pull request if you notice any integration problems.
Usage
Import the framework:
import KeyboardKit
Instead of creating or subclassing a UIKit class directly, use the subclasses from KeyboardKit instead. All KeyboardKit subclasses are named by changing UI
to Keyboard
. For example replace
class SettingsViewController: UICollectionViewController {
...
}
with
class SettingsViewController: KeyboardCollectionViewController {
...
}
Or create KeyboardKit subclasses directly:
let tabBarController = KeyboardTabBarController()
tabBarController.viewControllers = [
KeyboardNavigationController(rootViewController: SettingsViewController()),
]
In order to receive key commands, an object must be on the responder chain.
You can see more in the KeyboardKitDemo app, and each class includes API documentation in their Swift source file.
Approach to API and testing
The public API is currently kept minimal. Exposing more API without first understanding use-cases would increase the chances of having to make breaking API changes. If there is something you’d like to be able to customise in KeyboardKit, please open an issue to discuss.
KeyboardKit does not have many automated tests yet. This is a deliberate choice to invest time on the project where it is most valuable. If functionality is ever reported to be breaking then automated tests should be added at that point.
Credits
KeyboardKit is a project from Douglas Hill with the kind help of contributors. Some concepts were originally developed for PSPDFKit and reimplemented in Swift for KeyboardKit. I use KeyboardKit in my reading app.
Learn more
- Conference talk: Keyboard control in UIKit apps at iOS Conf SG 2020
- Podcast discussion: iPhreaks episode 297
- Blog post: What’s New in KeyboardKit for iOS 14?
Contributing
I’d love to have help on this project. For small changes please open a pull request, for larger changes please open an issue first to discuss what you’d like to see.
Licence
MIT license — see License.txt