有没有办法检测键盘类型的变化与大小,类型和建议栏高度,从英语键盘改为印地语,其中包含某种建议栏(见截图)。
普通英语键盘
第一个问题
更改为印地语LIPI后 - 当我改变时,因为英语和印地语键盘的大小相同,但是在开始输入印地语Lipi建议后覆盖TextField
第二个问题
更改为表情符号后 - 与英语相比,表情符号键盘的亮度稍高,因此键盘再次覆盖TextField
。
答案 0 :(得分:5)
为名为“UIKeyboardWillChangeFrameNotification”的通知添加观察者。
通知的“userInfo”字典在屏幕上有多个键盘框架。
添加观察者
- (void)logNotification:(NSNotification *)notification {
NSLog(@"%@", notification);
}
带记录器的选择器
userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = 0;
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 441.5}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 460}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 315}, {320, 253}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 352}, {320, 216}}";
UIKeyboardIsLocalUserInfoKey = 1;
}}
userInfo字典内容
_onNewFlowCreated(newFlow) {
let url= '/#/flows/'+ newFlow.uid +'/edit';
//window.history.pushState({}, '', url);
window.location.href= url;
}
答案 1 :(得分:3)
我也面临同样的问题。我通过使用下面的代码解决了
CGSize keyboardSize = [aNotification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
使用UIKeyboardFrameEndUserInfoKey而不是使用UIKeyboardFrameBeginUserInfoKey。
答案 2 :(得分:2)
Swift 4
注册观察员
NotificationCenter.default.addObserver(self,selector:#selector(KeyboardWillChangeFrame),name:NSNotification.Name.UIKeyboardWillChangeFrame,object: nil)
<强>功能强>
@objc func KeyboardWillChangeFrame(_ notification: Notification){
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight = keyboardSize.height
print("New Keyboard Height:",keyboardHeight)
}
}
答案 3 :(得分:0)
你需要按照屏幕上的显示获得键盘的高度
针对UIKeyboardWillShowNotification
和UIKeyboardWillHideNotification
通知注册观察者:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
设置键盘高度的全局变量:
CGFloat _currentKeyboardHeight = 0.0f;
实施 keyboardWillShow 和 keyboardWillHide 以对键盘高度的当前变化作出反应:
- (void)keyboardWillShow:(NSNotification*)notification {
NSDictionary *info = [notification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
CGFloat deltaHeight = kbSize.height - _currentKeyboardHeight;
// Write code to adjust views accordingly using deltaHeight
_currentKeyboardHeight = kbSize.height;
}
- (void)keyboardWillHide:(NSNotification*)notification {
NSDictionary *info = [notification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
// Write code to adjust views accordingly using kbSize.height
_currentKeyboardHeight = 0.0f;
}