Keyboardy 0.2.7

Keyboardy 0.2.7

测试已测试
Lang语言 SwiftSwift
许可 MIT
Released上次发布2020年1月
SPM支持 SPM

Andrew Podkovyrin维护。



Keyboardy 0.2.7

Keyboardy

Version Carthage Compatible Accio supported License Platform

描述

Keyboardy 通过少量简单方法扩展 UIViewController 并提供处理键盘出现通知的代理。

  • Keyboardy 仅是 UIKeyboardWillShowNotificationUIKeyboardWillHideNotification 通知的包装。
  • 支持 AutoLayout 和基于 frame 的动画。
  • Swift 实现。
  • 没有使用任何技巧,如方法交换和魔法数字(例如 curve << 16)。

Keyboardy Demo GIF

使用

  • 导入 Keyboardy 模块
import Keyboardy
  • 注册键盘通知
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    registerForKeyboardNotifications(self)
}
  • 注销键盘通知
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    unregisterFromKeyboardNotifications()
}
  • 实现 KeyboardStateDelegate
extension ViewController: KeyboardStateDelegate {

    func keyboardWillTransition(_ state: KeyboardState) {
        // keyboard will show or hide
    }

    func keyboardTransitionAnimation(_ state: KeyboardState) {
        switch state {
        case .activeWithHeight(let height):
            textFieldContainerBottomConstraint.constant = height
        case .hidden:
            textFieldContainerBottomConstraint.constant = 0.0
        }

        view.layoutIfNeeded()
    }

    func keyboardDidTransition(_ state: KeyboardState) {
        // keyboard animation finished
    }
}

示例

要运行示例项目,克隆仓库,然后首先从 Example 目录运行 pod install

需求

Swift 5, iOS 8

CocoaPods 安装

Keyboardy 可以通过 CocoaPods 获取。要安装它,只需在您的 Podfile 中添加以下行

pod "Keyboardy"

Carthage 安装

Carthage 是一个去中心化的依赖管理器,它自动将框架添加到您的 Cocoa 应用中。

您可以使用以下命令通过 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 将 Keyboardy 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它

github "podkovyrin/Keyboardy"

Accio 安装

  1. 将以下代码添加到您的 Package.swift

    .package(url: "https://github.com/podkovyrin/Keyboardy.git", .upToNextMajor(from: "0.2.7")),
  2. 接下来,将 Keyboardy 添加到您的 App targets 依赖项中,如下所示

    .target(name: "App", dependencies: ["Keyboardy"]),
  3. 然后运行 accio update

作者

Andrew Podkovyrin,[email protected]

许可证

Keyboardy 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。