下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、UIWebView 键盘的 accessoryBar 隐藏当前越来越多的 iOS 应用开始使用 html 进行交互显示,却会发现在 UIWebView 弹出的键盘比 UITextView 的键盘多出了左右移动以及完成按钮,那么如何去掉这些我们并不需要的按钮呢?苹果官方并没有给出方法,所以我们只能够自己来解决。 webview_keyboard.png对于不同的 iOS 版本,我们的处理方法也会不同,因为官方没有提供方法,所有的方法都是需要自己去发现和修改。这里只写出 iOS7 以上版本的方法:func hideKeyBoard() - V oid for window inUIApplicat
2、ion.sharedApplication().windows if !window.isMemberOfClass(UIWindow.self) let keyboardWindow = windowif #available(iOS 9.0, *) self.removeAccessoryBarForiOS9(keyboardWindow as UIView) else if #available(iOS 8.0, *) self.removeAccessoryBarForiOS8(keyboardWindow as UIView) else self.removeAccessoryBar
3、ForiOS7(keyboardWindow as UIView)if #available(iOS 9.0, *) self.removeAccessoryBarForiOS9(UIApplication.sharedApplica tion().windows.last! as UIView)funcremoveAccessoryBarForiOS9(keyboardWindow:UIView) -Void for possibleFormView:UIView inkeyboardWindow.subviews ifpossibleFormView.isMemberOfClass(NSC
4、lassFromString(UII nputSetContainerView)!) for subviewOfInputSetContainerView in possibleFormView.subviews ifsubviewOfInputSetContainerView.isMemberOfClass(NSClassFromString(UIInputSetHostView)!) for subviewOfInputSetHostViewin subviewOfInputSetContainerView.subviews / 隐藏工具条NSClassFromStringifsubvie
5、wOfInputSetHostView.isMemberOfClass(NSClassFromString(UIWebFormAccessory)!) subviewOfInputSetHostView.layer.opacity = 0subviewOfInputSetHostView.frame = CGRectZero else if(subviewOfInputSetHostView.isMemberOfClass(NSClassFrom String(_UIRemoteKeyboardPlaceholderView)!) subviewOfInputSetHostView.layer
6、.opacity = 0subviewOfInputSetHostView.frame = CGRectZero/ 这里使用了私有方法获取对应的accessorBar,然后进行隐藏var accessory =subviewOfInputSetHostView.performSelector(Selector(placeheldView).takeRetainedValue()ifaccessory.isMemberOfClass(NSClassFromString(UIWebFormAccessory)!) let accessory =accessory as! UIViewaccesso
7、ry.layer.opacity = 0accessory.frame =CGRectZero/ 键盘背景 ,UIKBInputBackdropView有两个只隐藏上面的else ifsubviewOfInputSetHostView.isMemberOfClass(NSClassFromString(UIKBInputBackdropView)!) &subviewOfInputSetHostView.frame.size.height Void for possibleFormView:UIView inkeyboardWindow.subviews ifpossibleFormView.
8、isMemberOfClass(NSClassFromString(UIInputSetContainerView)!) for subviewOfInputSetContainerView in possibleFormView.subviews ifsubviewOfInputSetContainerView.isMemberOfClass(NSClassFromString(UIInputSetHostView)!) for subviewOfInputSetHostViewin subviewOfInputSetContainerView.subviews / 隐藏工具条ifsubvi
9、ewOfInputSetHostView.isMemberOfClass(NSClassFromString(UIWebFormAccessory)!) subviewOfInputSetHostView.layer.opacity = 0subviewOfInputSetHostView.frame = CGRectZero/ 键盘背景 ,UIKBInputBackdropView有两个只隐藏上面的else ifsubviewOfInputSetHostView.isMemberOfClass(NSClassFromS tring(UIKBInputBackdropView)!) & sub
10、viewOfInputSetHostView.frame.size.height Void for possibleFormView:UIView inkeyboardWindow.subviews ifpossibleFormView.isMemberOfClass(NSClassFromString(UIPeripheralHostView)!) for subviewOfPeripheralHostView inpossibleFormView.subviews / 隐藏工具条ifsubviewOfPeripheralHostView.isMemberOfClass(NSClassFro
11、mString(UIWebFormAccessory)!) subviewOfPeripheralHostView.layer.opacity = 0subviewOfPeripheralHostView.frame = CGRectZero/ 键盘背景 ,UIKBInputBackdropView 有两个只隐藏上面的else ifsubviewOfPeripheralHostView.isMemberOfClass(NSClassFromString(UIKBInputBackdropView)!) &subviewOfPeripheralHostView.frame.size.height
12、 100 subviewOfPeripheralHostView.layer.opacity = 0subviewOfPeripheralHostView.userInteractionEnabled = false实际中,隐藏键盘accessory 后的样子如下图:webview_keyboard_hideaccessory.png需要注意的是,在示例代码使用设置layer 透明, frame 为空来进行隐藏,而不使用removeFromSuperView ,是因为使用了 removeFromSuperView ,在键盘重新布局时会导致crash。当然如果有朋友解决了crash,使用 rem
13、oveFromSuperView会更好。附:上面示例代码Github 地址使用 removeFromSuperView 产生 crash 的崩溃栈:2016-07-06 14:10:32.018 WebViewKeyBoard10846:930540 The view hierarchy is not prepared for the constraint:When added to a view, the constraints items must be descendants of that view (or the view itself). This will crash ifthe
14、 constraint needs to be resolved before the view hierarchy is assembled. Break on -UIView(UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint: to debug.2016-07-06 14:10:32.018 WebViewKeyBoard10846:930540* Assertion failure in -UIInputSetHostView_layoutEngine_didAddLayoutConstraint:roundin
15、gAdjustment:mutuallyExclusiveConstraints:,/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/NSLayoutConstraint_UIKitAdditions.m:5902016-07-06 14:10:32.025 WebViewKeyBoard10846:930540* Terminating app due to uncaught exception NSInternalInconsistencyException, reason: Impossib
16、le to set up layout with view hierarchy unprepared for constraint.* First throw call stack:(0CoreFoundation0x0000000105517d85 _exceptionPreprocess + 165 1 libobjc.A.dylib0x00000001072bbdeb objc_exception_throw + 48 2 CoreFoundation0x0000000105517bea +NSException raise:format:arguments: + 1063Foundat
17、ion0x0000000105968d5a -NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description: + 1984 UIKit 0x0000000106626b99_120-UIView(UIConstraintBasedLayout)_layoutEngine_didAddLayoutConstraint:roundingAdjustment:m utuallyExclusiveConstraints:_block_invoke_2 + 2545 UIKit0x000000010662698b
18、-UIView(UIConstraintBasedLayout)_layoutEngine_didAddLayoutConstraint:roundingAdjustment:m utuallyExclusiveConstraints: + 3856UIKit0x0000000106626e04 -UIView(UIConstraintBasedLayout)_tryToAddConstraintWithoutUpdatingConstraintsArray:roundin gAdjustment:mutuallyExclusiveConstraints: + 657UIKit0x000000
19、0106626f7d -UIView(UIConstraintBasedLayout)_tryToAddConstraint:roundingAdjustment:mutuallyExclusiveC onstraints: + 2888UIKit0x000000010662719f -UIView(UIConstraintBasedLayout)_addConstraint: + 2749UIKit0x0000000106627438 _50-UIView(UIConstraintBasedLayout) addConstraints:_block_invoke + 19710 Founda
20、tion 0x00000001058f23d3 -NSISEngine withBehaviors:performModifications: + 15511 UIKit0x0000000106626577 -UIView(UIConstraintBasedLayout)_withAutomaticEngineOptimizationDisabled: + 5812UIKit0x0000000106627348 -UIView(UIConstraintBasedLayout)addConstraints: + 37913UIKit0x00000001066b5531 -UIInputWindo
21、wControllerupdateViewConstraints + 355814UIKit0x00000001066b1fde -UIInputSetHostView_didChangeKeyplaneWithContext: + 22415UIKit0x000000010650f1cc -_UIKBCompatInputView_didChangeKeyplaneWithContext: + 87 16 UIKit0x0000000106004397 -UIKeyboard_didChangeKeyplaneWithContext: + 324 17 UIKit0x0000000105fe7b04 -UIKeyboardImpl_didChangeKeyplaneWithContext: + 110018 UIKit 0x000000010620d5a3-UIKeyboardLayoutStar(UIKeyboardLayoutJapanese50OnFlick) _didChangeKeyplaneWithContext: + 18319 UIKit0x00000001061f121e -UIKeyboardLayoutStar setKeyp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 历史隋唐时期的中外文化交流同步课件- -2025-2026学年统编版七年级历史下册
- 光学玻璃系列产品生产线项目可行性研究报告
- 住院医师规范化培训《口腔科》题库及参考答案
- 2025年12月住院医师规范化培训《儿科》模拟题及参考答案解析
- 鸟类美容服务项目可行性研究报告
- 新建7000万只纸质玩具包装盒生产线项目可行性研究报告
- 消化性溃疡护理业务学习
- 慢性支气管炎的中西医结合治疗研究
- 电厂锅炉的维护保养及检修规程
- 全民健身计划及健康生活指导手册
- 企业绩效管理系统的构建
- 《电视摄像教程》课件第6章
- 消化系统常见症状课件
- DISC性格分析与情绪管理课件
- 《小学生C++创意编程》第6单元课件-do-while循环
- 离婚协议书免费下载-完整离婚协议书
- 旅游产品策划与设计课件(完整版)
- 百凤冈厚积人文沃土和谐发展培育世纪英才
- ISO22000标准培训课件
- 【原创】高二数学校本课程教材:生活中的数学校本课程
- 钢筋笼加工与安装施工方案完整
评论
0/150
提交评论