반응형
iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShowInScroll), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHideInScroll), name: UIResponder.keyboardWillHideNotification, object: nil)
Notification 등록
@objc func keyboardWillShowInScroll(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}
let contentInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardFrame.size.height, right: 0.0)
scrollView.contentInset = contentInset
scrollView.scrollIndicatorInsets = contentInset
}
키보드 화면 처리
반응형
'iOS > 코드조각' 카테고리의 다른 글
[iOS, Swift] String to Data (Base64 Encoded String) (0) | 2022.07.13 |
---|---|
[iOS, Swift] 텍스트필드 AutoComplete 자동완성 기능 (0) | 2022.07.13 |
[iOS, Swift] ScrollView endEditing 사용하기 (0) | 2022.07.12 |
[iOS, Swift] Alamofire responseDecodable 사용하기 (0) | 2022.07.12 |
[iOS, Swift] 정규식(이메일, 아이디, 닉네임, 패스워드, 전화번호) (0) | 2022.07.12 |