반응형
키보드 show/hide에 따라서 키보드 높이를 사용해야 할때가 있습니다. 이때 Publisher로 처리 하는 방법은 다음과 같습니다.
var keyboardHeightPublisher: AnyPublisher<CGFloat, Never> {
Publishers.Merge(
NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)
.compactMap { $0.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect }
.map { $0.height }
NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)
.map { _ in CGFloat(0) }
).eraseToAnyPublisher()
}
반응형
'개발 > iOS' 카테고리의 다른 글
SwiftUI 에서 Background나 Foreground 진입시 처리 (0) | 2024.01.05 |
---|---|
Background, Foreground 진입시 처리 (0) | 2024.01.04 |
SegmentView (0) | 2023.12.30 |
UITextField hyphen(-) 연속 입력시 en dash(–)로 변경되는것 막기 (0) | 2023.12.14 |
TextField에 clearButton 추가하기 (0) | 2023.12.13 |
Warning "Non-constant range: argument must be an integer literal" (0) | 2023.12.07 |
SFSymbol의 Monochrome, Hierarchical, Palette, Multicolor Mode (1) | 2023.12.05 |
Custom Environment (1) | 2023.12.05 |