Keyboard
2020. 10. 23. 16:33ㆍ개발자료/iOS
반응형
## Swift
@objc func keyBoardWillShow(notification: NSNotification) {
let userInfo:NSDictionary = notification.userInfo! as NSDictionary
let keyboardFrame:NSValue = userInfo.value(forKey: UIResponder.keyboardFrameEndUserInfoKey) as! NSValue
let keyboardRectangle = keyboardFrame.cgRectValue
var keyboardHeight = keyboardRectangle.height
if #available(iOS 11.0, *) {
let bottomInset = view.safeAreaInsets.bottom
keyboardHeight -= bottomInset
}
self.keyboardtop.constant = keyboardHeight
}
## Obj-C
- (void)keyboardWillShown:(NSNotification*)notification{
NSDictionary* info = [notification userInfo];
CGFloat keyboardHeight = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
CGFloat bottomInset = 0;
if (@available(iOS 11.0, *)) {
bottomInset = self.view.safeAreaInsets.bottom;
keyboardHeight -= bottomInset
}
self.keyboardtop.constant = keyboardHeight
[self.view layoutIfNeeded];
}
반응형
'개발자료 > iOS' 카테고리의 다른 글
[Swift-OpenSource] scalessec / Toast-Swift (0) | 2020.11.02 |
---|---|
Interface Builder TableView Separator Line (0) | 2020.11.02 |
Apple 푸시 알림 서비스 업데이트 (0) | 2020.10.12 |
Xcode 12로 빌드하기(2021년 4월부터 리젝) (0) | 2020.10.06 |
AVPlayerViewController 사용 (0) | 2020.09.25 |