ALSKeyboardLayoutGuide
示例
要运行示例项目,先克隆仓库,然后从 Example 目录中首先运行 pod install
。
示例代码
let label = UILabel()
label.textColor = .black
label.text = "I'm above keyboard and inside safe area!"
view.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
label.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
label.bottomAnchor.constraint(lessThanOrEqualTo: view.keyboardLayoutGuide.topAnchor, constant: -8.0).isActive = true
if #available(iOS 11.0, *) {
label.bottomAnchor.constraint(lessThanOrEqualTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -8.0).isActive = true
} else {
label.bottomAnchor.constraint(lessThanOrEqualTo: view.bottomAnchor, constant: -8.0).isActive = true
}
let constraint = label.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0)
constraint.priority = UILayoutPriority(1)
constraint.isActive = true
安装
CocoaPods
ALSKeyboardLayoutGuide 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'ALSKeyboardLayoutGuide'
手动
将 ALSKeyboard.swift
和 UIView+KeyboardLayoutGuide.swift
文件拖动到 ALSKeyboardLayoutGuide/Classes
目录中进入您的项目。
使用说明
使用view.keyboardLayoutGuide
属性进行子视图布局。
注意:视图的大小应与窗口或屏幕相同。换句话说,它主要是视图控制器的视图。
作者
Adelais0
许可证
ALSKeyboardLayoutGuide遵循MIT许可证。更多详情请参阅LICENSE文件。