{"id":20685057,"url":"https://github.com/geri-borbas/ios.blog.keyboard_avoidance","last_synced_at":"2025-09-27T04:31:53.195Z","repository":{"id":70887393,"uuid":"477033490","full_name":"Geri-Borbas/iOS.Blog.Keyboard_Avoidance","owner":"Geri-Borbas","description":"⌨️ Keyboard avoidance with a single line of code. Animate to text fields, swipe down keyboard dismissal for free.","archived":false,"fork":false,"pushed_at":"2022-04-22T16:06:07.000Z","size":99,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-16T22:28:56.873Z","etag":null,"topics":["avoidance","ios","keyboard","keyboardlayoutguide","swift","uikit","uilayoutguide","uitextfield"],"latest_commit_sha":null,"homepage":"https://blog.eppz.eu/keyboard-avoidance/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Geri-Borbas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2022-04-02T11:23:39.000Z","updated_at":"2024-10-25T09:20:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"b06c3e72-62ae-41ea-803b-5c7a815b3da4","html_url":"https://github.com/Geri-Borbas/iOS.Blog.Keyboard_Avoidance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FiOS.Blog.Keyboard_Avoidance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FiOS.Blog.Keyboard_Avoidance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FiOS.Blog.Keyboard_Avoidance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FiOS.Blog.Keyboard_Avoidance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Geri-Borbas","download_url":"https://codeload.github.com/Geri-Borbas/iOS.Blog.Keyboard_Avoidance/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234390521,"owners_count":18824621,"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":["avoidance","ios","keyboard","keyboardlayoutguide","swift","uikit","uilayoutguide","uitextfield"],"created_at":"2024-11-16T22:25:22.388Z","updated_at":"2025-09-27T04:31:47.889Z","avatar_url":"https://github.com/Geri-Borbas.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Keyboard Avoidance\n\n⌨️ Keyboard avoidance with a single line of code. Animate to text fields (or any responder), swipe down keyboard dismissal for free. See the corresponding article for more [Keyboard Avoidance with a single line of code], also on detail how to backport `keyboardLayoutGuide` to iOS 13 and iOS 14.\n\nhttps://user-images.githubusercontent.com/1779614/163884587-c11f4953-2f30-4b46-b36f-1fac9b32a017.mp4\n\n## How\n\n1. Put everything in a scroll view.\n2. Pin the bottom of the scroll view to the top of the `keyboardLayoutGuide`.\n3. Set `keyboardDismissMode` to `.onDrag`.\n\n```Swift\nclass ViewController: UIViewController {\n    \n    lazy var emailTextField = UITextField()\n        .withEmailStyle\n        .with(next: givenNameTextField)\n    \n    lazy var givenNameTextField = UITextField()\n        .withGivenNameStyle\n        .with(next: familyNameTextField)\n    \n    lazy var familyNameTextField = UITextField()\n        .withFamilyNameStyle\n        .with(next: passwordTextField)\n    \n    lazy var passwordTextField = UITextField()\n        .withPasswordStyle\n    \n    lazy var signUpButton = UIButton()\n        .withSignUpButtonStyle\n    \n    lazy var content = UIStackView()\n        .vertical(spacing: UI.spacing)\n        .views(\n            HeaderView()\n                .withFixedHeight,\n            emailTextField,\n            givenNameTextField,\n            familyNameTextField,\n            passwordTextField,\n            signUpButton\n        )\n    \n    lazy var body = UIScrollView()\n        .with {\n            $0.addSubview(content)\n\n            // 💎\n            $0.keyboardDismissMode = .onDrag\n            $0.bounces = false\n        }\n        .onMoveToSuperview { scrollView in\n            self.content.pin(to: scrollView)\n            self.content.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true\n        }\n    \n    var bottomConstraint: NSLayoutConstraint?\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        view.backgroundColor = .systemBackground\n        \n        // Hierarchy.\n        view.addSubview(body)\n        body.translatesAutoresizingMaskIntoConstraints = false\n        body.topAnchor.constraint(equalTo: view.topAnchor, constant: UI.padding).isActive = true\n\n        // 💎\n        body.bottomAnchor.constraint(\n            equalTo: view.keyboardLayoutGuide.topAnchor,\n            constant: -UI.spacing\n        ).isActive = true\n\n        body.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: UI.spacing).isActive = true\n        body.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -UI.spacing).isActive = true\n    }\n}\n```\n\n\u003e The example above uses [`Withable`], a simple inline decorator that helps simplify your `UIKit` code.\n\n\n## License\n\n\u003e Licensed under the [**MIT License**](https://en.wikipedia.org/wiki/MIT_License).\n\n\n[Keyboard Avoidance with a single line of code]: https://blog.eppz.eu/keyboard-avoidance/\n[`Withable`]: https://github.com/Geri-Borbas/iOS.Package.Withable\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeri-borbas%2Fios.blog.keyboard_avoidance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeri-borbas%2Fios.blog.keyboard_avoidance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeri-borbas%2Fios.blog.keyboard_avoidance/lists"}