ios 隐藏键盘的toolbar H5键盘
2019-12-01 本文已影响0人
木子李55
// 因为原生键盘如果不额外设置,toolbar本来就是不出现的,
而H5页面调起的键盘默认toolbar默认是出现的,有的时候键盘太高会遮住输入框,所以需要隐藏掉这部分。
//** 隐藏webview键盘的toolbar(wkwebview和uiwebview通用)
// 在加载页面时加入监听键盘出来的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willshowKeyBoardClick) name:UIKeyboardWillShowNotification object:nil];
// 页面消失时移除监听
[[NSNotificationCenter defaultCenter] removeObserver:self];
// 键盘弹起监听
- (void)willshowKeyBoardClick{
NSArray *arr = [UIApplication sharedApplication].windows;
for (NSInteger i = 0; i < arr.count; i++) {
if ([arr[i] isKindOfClass:[NSClassFromString(@"UITextEffectsWindow") class]]) {
if (![arr[i] isKindOfClass:[NSClassFromString(@"UIRemoteKeyboardWindow") class]]) {
UIWindow *window = arr[i];
UIView *view = [window.rootViewController.view.subviews lastObject];
if (view.subviews.count > 1) {
for (NSInteger j = 0;j < view.subviews.count; j++) {
if ([view.subviews[j] isKindOfClass:NSClassFromString(@"UIKBInputBackdropView")] ||
[view.subviews[j] isKindOfClass:NSClassFromString(@"UIWebFormAccessory")]) {
UIView *subView = view.subviews[j];
subView.alpha = 0.0;
}
}
break;
}
}
}
}
}