ScrollViewKeyboardAvoider
调整 UIScrollView
内的间距,以便键盘不会覆盖内容。
安装
最低部署目标:iOS 10.0(在 iOS 11 中使用 Safe Area Layout 以兼容 iPhone X)
CocoaPods
你可以使用CocoaPods将 ScrollViewKeyboardAvoider
与你的项目集成。只需在你的 Podfile
中添加以下行:
pod 'ScrollViewKeyboardAvoider', '~> 1.0'
Carthage
如果你更喜欢使用 Carthage,也可以通过在 Cartfile
中添加以下行来实现:
github "darrarski/ScrollViewKeyboardAvoider" ~> 1.0
使用
您需要设置键盘框架观察,如果需要简单解决方案,请参阅KeyboardFrameChangeListener。您还可以查看将自定义视图包装并自动处理所有逻辑的ScrollViewController。
示例可以在DemoApp中找到。
简化版内容
let avoider: ScrollViewKeyboardAvoiding = ScrollViewKeyboardAvoider(
animator: { UIView.animate(withDuration: $0, animations: $1) }
)
let scrollView: UIScrollView
let newKeyboardFrame: CGRect
let keyboardAnimationDuration: TimeInterval
avoider.handleKeyboardFrameChange(newKeyboardFrame,
animationDuration: keyboardAnimationDuration,
for: scrollView)
开发
要求
- Ruby 配合 Bundler
- Xcode 10
要引导项目运行
bundle install
bundle exec fastlane setup
然后,在 Xcode 中打开 ScrollViewKeyboardAvoider.xcodeproj
。
使用 DemoApp
构建方案进行构建和运行示例应用程序。
使用 Tests
构建方案运行测试。
要从命令行运行测试,执行
bundle exec fastlane test
要生成和以 HTML 格式打开测试覆盖率报告,运行
bundle exec fastlane coverage
许可证
MIT 许可证 - 请参阅 LICENSE 文件。