H5页面有个input设置了readOnly,禁止弹窗系统键盘,用户点击改input,前端通知iOS客户端弹起自定义键盘,但是操作系统在iOS11 - iOS12 左右部分机型会出现屏幕底部出现toolBar,也就是说前端H5通过设置readOnly禁止弹起系统键盘,但是低版本iOS操作系统 系统软键盘toolBar还是会出现
解决方法:
alpha 控制系统toolBar显示还是隐藏
CGFloat alpha = isShowAmountKeyboard ? 0.0 : 1.0;
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 = alpha;
}
}
break;
}
}
}
}
但是问题是需要改input成为焦点的时候隐藏toolBar,input失去焦点的时候隐藏toolBar
包含自己项目的业务逻辑时的解决方法:
给web容器的控制器增加属性isShowAmountKeyboard,通过重写setter方法控制系统键盘toolBar显示和隐藏,在相应的逻辑出设置控制器的isShowAmountKeyboard = YES or NO
// 金额键盘是否被弹起
@property (nonatomic, assign)BOOL isShowAmountKeyboard;
// 金额键盘出现时隐藏toolBar,金额键盘消失时展示toolBar
- (void)setIsShowAmountKeyboard:(BOOL)isShowAmountKeyboard {
_isShowAmountKeyboard = isShowAmountKeyboard;
CGFloat alpha = isShowAmountKeyboard ? 0.0 : 1.0;
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 = alpha;
}
}
break;
}
}
}
}
}