{"id":13688484,"url":"https://github.com/niw/KeyboardGuide","last_synced_at":"2025-05-01T19:31:02.846Z","repository":{"id":56557966,"uuid":"243292783","full_name":"niw/KeyboardGuide","owner":"niw","description":"A modern, real iOS keyboard system notifications handler framework that Just Works.","archived":false,"fork":false,"pushed_at":"2024-03-08T22:52:17.000Z","size":692,"stargazers_count":459,"open_issues_count":0,"forks_count":15,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-05T04:14:43.322Z","etag":null,"topics":["ios","objective-c","swift","uikit"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-26T15:11:42.000Z","updated_at":"2025-01-27T16:35:52.000Z","dependencies_parsed_at":"2024-01-17T06:47:23.229Z","dependency_job_id":"72958a45-4892-4d8b-96c2-4f411001accb","html_url":"https://github.com/niw/KeyboardGuide","commit_stats":{"total_commits":41,"total_committers":1,"mean_commits":41.0,"dds":0.0,"last_synced_commit":"84e36334aeb537548a975282bf4b58485e140b23"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niw%2FKeyboardGuide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niw%2FKeyboardGuide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niw%2FKeyboardGuide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niw%2FKeyboardGuide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niw","download_url":"https://codeload.github.com/niw/KeyboardGuide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251932639,"owners_count":21667185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","objective-c","swift","uikit"],"created_at":"2024-08-02T15:01:14.884Z","updated_at":"2025-05-01T19:31:01.865Z","avatar_url":"https://github.com/niw.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# KeyboardGuide\n\nA modern, real iOS keyboard system notifications handler framework that Just Works.\n\n![KeyboardGuide](Resources/KeyboardGuide.png)\n\nAs you know, handling the keyboard on iOS was just a nightmare.\n\nOn the internet, there are many, many iOS keyboard handler implementations for system notifications such as `UIResponder.keyboardWillChangeFrameNotification` (`UIKeyboardWillChangeFrameNotification`), but most of them are not implemented properly.\n\nFor example, many of them are not converting the keyboard frame in the right coordinate or not considering iPad keyboard behaviors.\nAlso, there are many undocumented behaviors that are not consistent between each iOS version.\n\nThis framework is solving this problem.\n\nBased on years experience of iOS application development and various tests on each iOS version and device, it supports both Swift and Objective-C and works mostly reasonably on the latest 3 versions of iOS, which is iOS 11, 12 and iOS 13 now, and covers almost all iOS users.\n\n## Usage\n\nUsing `KeyboardGuide` is really simple. See also [Examples](Examples/) for actual usage, that contains Swift and Objective-C code for testing.\n\n### Add KeyboardGuide framework to your project\n\nAdd the following lines to your `Package.swift` or use Xcode “Add Package Dependency…” menu.\n\n```swift\n// In your `Package.swift`\n\ndependencies: [\n    // ...\n    .package(url: \"https://github.com/niw/KeyboardGuide.git\"),\n    // ...\n]\n```\n\n### Using KeyboardGuide with the other dependency management tools.\n\n`KeyboardGuide` doesn’t support directly the other dependency management tools than Swift Package Manager and CocoaPods.\nIt is highly recommend to use Swift Package Manager, if possible.\nHowever, since it has no dependencies other than system frameworks, you can still use it from the other dependency management tools.\n\n#### CocoaPods\n\nTo use `KeyboardGuide` from [CocoaPods](https://cocoapods.org/), add following line in your `Podfile`.\n\n```ruby\npod 'KeyboardGuide'\n```\n\n#### Carthage\n\nTo use `KeyboardGuide` from [Carthage](https://github.com/Carthage/Carthage), update `Cartfile` in your project.\n\n```\ngithub \"niw/KeyboardGuide\"\n```\n\nThen, run following commands. This will create `Carthage/Build/iOS/KeyboardGuide.framework`.\n\n```\n$ carthage update\n$ (cd Carthage/Checkouts/KeyboardGuide \u0026\u0026 swift package generate-xcodeproj)\n$ carthage build --platform iOS\n```\n\nFollow [the instruction](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos) to add the framework and Run Script phase to your project.\n\n### Setup KeyboardGuide\n\nAdd `import KeyboardGuide`.\n\nUse `KeyboardGuide.shared.activate()` to activate KeyboardGuide at the beginning of application life cycle, such as `application(_:didFinishLaunchingWithOptions:)`.\n\n```swift\n// In your `UIApplicationDelegate`\n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n    KeyboardGuide.shared.activate()\n    // ...\n}\n```\n\n### Add constraints on your views\n\nLay out your views by adding constraints to `view.keyboardSafeArea.layoutGuide`, where represents the safe area from, not covered by the keyboard.\n\nIt works as like `safeAreaLayoutGuide` for the notch.\n\n```swift\n// In your `UIViewController`\n\noverride func viewDidLoad() {\n    super.viewDidLoad()\n    // ...\n    let textView = UITextView()\n    textView.translatesAutoresizingMaskIntoConstraints = false\n    // ...\n    textView.bottomAnchor.constraint(equalTo: view.keyboardSafeArea.layoutGuide.bottomAnchor).isActive = true\n    // ...\n}\n```\n\n### Manual layout\n\nIf you prefer to manually lay out your views or need to use length of keyboard safe area, for such as updating `UIScrollView`’s `contentInset`, override `viewDidLayoutSubviews()` or `layoutSubviews()` as like regular manual lay outing.\n\n```swift\n// In your `UIViewController`\n\noverride func viewDidLayoutSubviews() {\n    super.viewDidLayoutSubviews()\n    // ...\n    let bottomInset = view.keyboardSafeArea.insets.bottom\n    textView.contentInset.bottom = bottomInset\n    textView.scrollIndicatorInsets.bottom = bottomInset\n}\n```\n\n#### The important layout behavior\n\nIf your `view` doesn’t have any sub views that have at least one constraint to `view.keyboardSafeArea.layoutGuide`, UIKit _MAY NOT_ call `layoutSubviews` (or similar callbacks such as `viewDidLayoutSubviews`).\n\nBecause in general, the keyboard safe area has a relative layout relationship between the keyboard position where is outside of the `view` but in the screen, UIKit doesn’t know that relationship without a constraint.\n\nFor example, on iOS 13, if a view controller is presented as a modal on iPad in portrait, when the keyboard is appearing, that modal view controller is moved upwards by UIKit.\nThis move changes the relative position of your `view` to the keyboard, however, UIKit doesn’t call your `layoutSubviews` (which is obvious,) but for keyboard safe area, you _MAY_ need to re lay out your sub views.\n\nTherefore, you _MAY_ need to add at least one constraint to `view.keyboardSafeArea.layoutGuide` from one of your sub views, to let UIKit knows `view` has that relationship.\n\n## Known limitations\n\nThere are a few known limitations in the current implementation.\nAll limitations are currently To-Do of this project.\n\n- No SwiftUI support yet.\n\n- Share extension can’t use this library yet because of `UIApplication` dependency.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniw%2FKeyboardGuide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniw%2FKeyboardGuide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniw%2FKeyboardGuide/lists"}