티스토리 뷰
UIKeyboardFrameBeginUserInfoKey, UIKeyboardFrameEndUserInfoKey
91haba 2017. 11. 8. 16:22
func adjustKeyboardHeight(_ show:Bool, _ notification:NSNotification){
if let keyboardFrame = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
var userInfo = notification.userInfo!
let animationDuration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as! TimeInterval
let changeInHeight = ( keyboardFrame.height ) * (show ? 1 : -1)
print(keyboardFrame)
if #available(iOS 11, *){
print("addtional")
print(changeInHeight)
--> 키보드의 높이값을 가져오지 못하는 문제
UIKeyboardFrameBeginUserInfoKey -> UIKeyboardFrameEndUserInfoKey
self.additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: changeInHeight , right: 0)
}
UIView.animate(withDuration: animationDuration, animations: {
if show{
if #available(iOS 11, *) {
self.view.layoutIfNeeded()
}
else{
self.scrollBottom.constant += changeInHeight
if self.scrollBottom.constant > changeInHeight{
self.scrollBottom.constant = changeInHeight
}
}
}//if show
else{
self.scrollBottom.constant = 0
}
})
}//if let keyboardSize
}
옵저버를 달았는데도 키보드의 높이값을 제대로 가져오지 못해서 헤맸는데 원인은 매우 간단한데에 있었다.
두 가지를 상황에 따라 적절히 구분지어서 사용해야겠다.
UIKeyboardFrameBeginUserInfoKey -> UIKeyboardFrameEndUserInfoKey
UIKeyboardFrameBeginUserInfoKey
'iOS > Debugging' 카테고리의 다른 글
[Debugging] dyld: Library not loaded: @rpath/libswiftCore.dylib (0) | 2018.02.05 |
---|---|
[Debugging, 앱 배포] iTunes Connect에 업로드한 빌드가 보이지 않을 때 (0) | 2018.01.30 |
[Debugging] iPhone X bottom SafeArea(layoutGuide) constraint issue (0) | 2018.01.19 |
[swift 3] extension userdefault (0) | 2017.09.21 |