CombineKeyboard
CombineKeyboard 是一种使用 Combine 获取键盘框架或高度的途径,灵感来自 RxSwift 社区的 RxKeyboard 库。
用法
CombineKeyboard 提供了三个 Publisher
。 (如果您想要更多的 Publisher,您可以贡献这个库)
/// A publisher emitting current keyboard `frame`
/// You will be returned the current keyboard `frame` at start of subscription.
public var frame: AnyPublisher<CGRect, Never>
/// A publisher emitting current keyboard `height`
/// You will be returned the current keyboard `height` at start of subscription.
public var height: AnyPublisher<CGFloat, Never>
/// A publisher emitting current keyboard `height` when keyboard's height is updated
public var heightUpdated: AnyPublisher<CGFloat, Never>
您可以与 CombineKeyboard.shared
一起使用这三个 Publisher
。
CombineKeyboard.shared.frame
.sink(receiveValue: { frame: CGRect in
print(frame)
})
.store(in: &cancellables)
CombineKeyboard.shared.height
.sink(receiveValue: { currentHeight: CGFloat in
print(currentHeight)
})
.store(in: &cancellables)
CombineKeyboard.shared.heightUpdated
.sink(receiveValue: { height: CGFloat in
print(height)
})
.store(in: &cancellables)
要求
- Swift 5
- iOS 13+
安装
CombineKeyboard 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中即可。
pod 'CombineKeyboard'
授权
CombineKeyboard遵循MIT许可证。更多信息请参阅LICENSE文件。
本库受到RxKeyboard库的启发。感谢RxKeyboard的贡献者。