{"id":17046880,"url":"https://github.com/stevebarnegren/sbkeyboardevents","last_synced_at":"2025-03-23T03:27:17.397Z","repository":{"id":62453392,"uuid":"79958337","full_name":"SteveBarnegren/SBKeyboardEvents","owner":"SteveBarnegren","description":"Easily respond to iOS keyboard appearance","archived":false,"fork":false,"pushed_at":"2019-05-31T20:37:08.000Z","size":62,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-02T09:04:33.213Z","etag":null,"topics":["appear","constraint","ios","keyboard","layout","uikit"],"latest_commit_sha":null,"homepage":null,"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/SteveBarnegren.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-24T21:54:33.000Z","updated_at":"2019-07-03T01:14:44.000Z","dependencies_parsed_at":"2022-11-01T23:46:36.085Z","dependency_job_id":null,"html_url":"https://github.com/SteveBarnegren/SBKeyboardEvents","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FSBKeyboardEvents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FSBKeyboardEvents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FSBKeyboardEvents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FSBKeyboardEvents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SteveBarnegren","download_url":"https://codeload.github.com/SteveBarnegren/SBKeyboardEvents/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245052399,"owners_count":20553160,"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":["appear","constraint","ios","keyboard","layout","uikit"],"created_at":"2024-10-14T09:47:42.726Z","updated_at":"2025-03-23T03:27:17.371Z","avatar_url":"https://github.com/SteveBarnegren.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SBKeyboardEvents\n\n[![Version](https://img.shields.io/cocoapods/v/SBKeyboardEvents.svg?style=flat)](http://cocoapods.org/pods/SBKeyboardEvents)\n[![License](https://img.shields.io/cocoapods/l/SBKeyboardEvents.svg?style=flat)](http://cocoapods.org/pods/SBKeyboardEvents)\n[![Platform](https://img.shields.io/cocoapods/p/SBKeyboardEvents.svg?style=flat)](http://cocoapods.org/pods/SBKeyboardEvents)\n\nSBKeyboardEvents makes it easy to repond to keyboard events without having to write the same boilerplate code in every view controller. No more subscribing to a bunch of Notifications in viewDidLoad!\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Installation\n\nSBKeyboardEvents is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"SBKeyboardEvents\"\n```\n\n## Usage\n\nYour ViewController (or other class, if you like), should implement the 'KeyboardEventListener' protocol. It should then register itself for keyboard events should with the `SBKeyboardEvents` singleton:\n\n######(There are methods for unsubscribing a listener, but this is handled automatically when the class is deallocated, so in practice, these methods should very rarely be required. It is safe subscribe and forget. SBKeyboardEvents keeps a weak reference to listeners, so it will not retain them)\n\n```swift\noverride func viewDidLoad() {\n\tsuper.viewDidLoad()\n        \n\tSBKeyboardEvents.addListener(self)\n}\n\n```\n\nFor the simplest implementation, you only need to implement a single method, `animateForKeyboardHeight(height:)`\n\nThis method is called from within the keyboard appearance/disappearance animation block, so adjust constraints/frames, and the rest will be handled automatically. Note that the height here, is the keyboard height from the bottom of the screen.\n\n```swift\nextension GameSetupViewController: KeyboardEventListener {\n    \n    func animateForKeyboardHeight(_ height: CGFloat) {\n         \n        keyboardPaddingConstraint.constant = height;\n        view.setNeedsLayout()\n        view.layoutIfNeeded()\n    }\n}\n```\n\nThis is the full Protocol declaration:\n\n```swift\npublic protocol KeyboardEventListener : class {\n    \n    func keyboardWillAppear()\n    func keyboardDidAppear()\n    func keyboardWillHide()\n    func keyboardDidHide()\n    func keyboardWillChangeFrame(_ frame: CGRect)\n    func keyboardDidChangeFrame(_ frame: CGRect)\n    func animateForKeyboardFrame(_ frame: CGRect)\n    func animateForKeyboardHeight(_ height: CGFloat)\n}\n```\n\nFunctions containing 'will' occur before the animation.\n\nFunctions containing 'did' occur after the animation.\n\nFunctions starting 'animate' are called from within the keyboard animation block\n\n## Author\n\nSteve Barnegren, steve.barnegren@gmail.com\n\n[@SteveBarnegren](https://twitter.com/stevebarnegren)\n\n## License\n\nSBKeyboardEvents is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevebarnegren%2Fsbkeyboardevents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevebarnegren%2Fsbkeyboardevents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevebarnegren%2Fsbkeyboardevents/lists"}