TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2017 |
Maintained by liuzhiyi1992.
- (void)adaptiveViewHandleWithAdaptiveView:(UIView *)adaptiveView, ...
, 可不传入适配页面所属的controller第三方键盘分次弹出问题:
ZYKeyboardUtil 通过对每次键盘展开时的增量heightIncrement作处理 应对 第三方键盘 分次弹出的问题
同时能处理多层嵌套情况下控件的键盘遮盖问题
UITextField嵌套两层UIView例子演示:
一个页面内多个输入控件处理:(可逐个传入,可传入共同superView)
创建一个ZYKeyboard对象,为了让其生存在整个页面实现功能的时间段内,让你的controller持有他吧。
self.keyboardUtil = [[ZYKeyboardUtil alloc] init];
配置animateWhenKeyboardAppearAutomaticAnimBlock,即可全自动处理键盘升降遮挡输入控件问题,且控件resignFirstResponder后自动还原。
只需在Block里利用参数keyboardUtil调用adaptiveViewHandleWithController:adaptiveView:,第一个参数为当前页面controller,第二个参数接收一个可变参数,为当前页面内的单个/多个输入控件或者包裹输入控件的View。
__weak ViewController *weakSelf = self;
[_keyboardUtil setAnimateWhenKeyboardAppearAutomaticAnimBlock:^(ZYKeyboardUtil *keyboardUtil) {
[keyboardUtil adaptiveViewHandleWithController:weakSelf adaptiveView:weakSelf.inputViewOne, weakSelf.inputViewSecond, weakSelf.inputViewThird, weakSelf.inputViewFourth, nil];
}];
or you can write like this convenient: (KeyboardUtil can find the controller itself)
__weak ViewController *weakSelf = self;
[_keyboardUtil setAnimateWhenKeyboardAppearAutomaticAnimBlock:^(ZYKeyboardUtil *keyboardUtil) {
[keyboardUtil adaptiveViewHandleWithAdaptiveView:weakSelf.inputViewOne, weakSelf.inputViewSecond, weakSelf.inputViewThird, weakSelf.inputViewFourth, nil];
}];
Attach:
另外提供自定义处理键盘升/降遮挡输入控件处理(自定义处理方案优先级高于自动处理方案):
[_keyboardUtil setAnimateWhenKeyboardAppearBlock:^(int appearPostIndex, CGRect keyboardRect, CGFloat keyboardHeight, CGFloat keyboardHeightIncrement) {
//do something when keyboard appear
}];
[_keyboardUtil setAnimateWhenKeyboardDisappearBlock:^(CGFloat keyboardHeight) {
//do something when keyboard dismiss
}];
[_keyboardUtil setPrintKeyboardInfoBlock:^(ZYKeyboardUtil *keyboardUtil, KeyboardInfo *keyboardInfo) {
//you can get keyboardInfo hear when animation ended
}];
ZYKeyboardUtil 通过lazy方式注册键盘通知监听者,核心工作围绕一个model和四个Block(一个主功能Block和三个附加Block),内部类KeyboardInfo作为model存储着每次处理时所需的键盘信息。animateWhenKeyboardAppearAutomaticAnimBlock作全自动处理,animateWhenKeyboardAppearBlock作键盘展示时的处理,animateWhenKeyboardDisappearBlock作键盘收起时的处理,而printKeyboardInfoBlock用作在必要时输出键盘信息。AppearBlock和DisappearBlock统一做了UIViewAnimation,自定义处理事件时只需要编写需要的界面变化即可。
property:
func:
property:
That all, thanks。
ZYKeyboardUtil is available under the MIT license. See the LICENSE file for more info.