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];
}

 

 

반응형