GithubHelp home page GithubHelp logo

liuzhiyi1992 / zykeyboardutil Goto Github PK

View Code? Open in Web Editor NEW
422.0 15.0 99.0 1.42 MB

一个Block,全自动处理键盘遮挡输入控件问题。Util Handed all keyboard events with Block Conveniently

Objective-C 78.05% Ruby 21.95%

zykeyboardutil's Introduction

ZYKeyboardUtil

Util Handled all keyboard events with Block Conveniently
只需要一个Block,全自动处理任何多层嵌套复杂界面 因键盘升降 造成的输入控件遮挡问题。
第三方键盘分次弹出问题



- 1.0.7开放keyboardTopMargin属性,定制键盘与控件间隙。优化寻找firstResponder遍历逻辑,去除static引用不释放隐患。 - 1.0.6更新寻找firstResponder递归算法,解决潜在memory leak - 1.0.5优化键盘收起时界面恢复的逻辑 - 1.0.4增加API```- (void)adaptiveViewHandleWithAdaptiveView:(UIView *)adaptiveView, ...```, 可不传入适配页面所属的controller - 1.0.3稳定版本,取消1.0.2新增特性(出现代理无法使用问题,暂停使用) - 1.0.2处理 同一页面多个输入控件时不收键盘而直接转移第一响应者到另一被半遮盖输入控件 界面没有适配动作问题(在当前输入控件注 销第一响应者时,会重复再触发一次与上次相同的遮盖计算) - 0.6.1优化 对UITextView的处理,优化 部分方法实现 - 0.5.1处理 输入控件在多层嵌套view内 有时不能找到firstResponder 的问题 - 0.4.1支持一个页面多个输入控件处理(全自动处理键盘升降遮挡输入控件问题) (仅需配置animateWhenKeyboardAppearAutomaticAnimBlock) - 0.3.1更新自动处理键盘收起时对界面的还原(需与全自动升起处理同时使用, 无需配置animateWhenKeyboardDisappearBlock) - 0.2.1更新全自动处理键盘遮盖事件(需配置animateWhenKeyboardAppearAutomaticAnimBlock),具体使用参照Demo

#Features: 第三方键盘分次弹出问题:
ZYKeyboardUtil 通过对每次键盘展开时的增量heightIncrement作处理 应对 第三方键盘 分次弹出的问题


**同时能处理多层嵌套情况下控件的键盘遮盖问题** UITextField嵌套两层UIView例子演示:


一个页面内多个输入控件处理:(可逐个传入,可传入共同superView)


UITextView处理:


#CocoaPods:
pod 'ZYKeyboardUtil', '~> 1.0.7'


#Usage:
创建一个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:** 另外提供自定义处理键盘升/降遮挡输入控件处理(自定义处理方案优先级高于自动处理方案): ```objc [_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 }];

<br>


#**explain:**  
ZYKeyboardUtil 通过lazy方式注册键盘通知监听者,核心工作围绕一个model和四个Block(一个主功能Block和三个附加Block),内部类KeyboardInfo作为model存储着每次处理时所需的键盘信息。animateWhenKeyboardAppearAutomaticAnimBlock作全自动处理,animateWhenKeyboardAppearBlock作键盘展示时的处理,animateWhenKeyboardDisappearBlock作键盘收起时的处理,而printKeyboardInfoBlock用作在必要时输出键盘信息。AppearBlock和DisappearBlock统一做了UIViewAnimation,自定义处理事件时只需要编写需要的界面变化即可。
  
<br>

###Class:
####-KeyboardInfo:
**property:**  
- animationDuration:  响应动画的过程时长  
- frameBegin:触发键盘事件前键盘frame  
- frameEnd:变化后键盘frame  
- heightIncrement:单次键盘变化增量  
- action:键盘事件枚举  
- isSameAction:是否同一种动作    

**func:**  
- fillKeyboardInfoWithDuration:frameBegin:frameEnd:heightIncrement:action:isSameAction:    
为KeyboardInfo各属性赋值。  

####-ZYKeyboardUtil:  
**property:**  
- appearPostIndex:键盘分次弹出情况中 弹出 的次数
- keyboardInfo  
- haveRegisterObserver:是否已经注册监听者  
- animateWhenKeyboardAppearBlock:弹出Block  
- animateWhenKeyboardDisappearBlock:收起Block  
- printKeyboardInfoBlock:输出键盘信息Block    
- animateWhenKeyboardAppearBlockAutomaticAnim:全自动处理键盘遮盖事件Block   
**func:**  
- setAnimateWhenKeyboardAppearBlock:    
- setAnimateWhenKeyboardDisappearBlock:  
- setPrintKeyboardInfoBlock:    
- setAnimateWhenKeyboardAppearBlockAutomaticAnim:  
- setAnimateWhenKeyboardAppearAutomaticAnimBlock:  

<br>

That all, thanks。
<br>
#**License:** 
ZYKeyboardUtil is available under the MIT license. See the LICENSE file for more info.

zykeyboardutil's People

Contributors

liuzhiyi1992 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zykeyboardutil's Issues

一个视图中有多个输入控件的时候,自动处理的触发问题

一个视图上有多个输入控件,比如两个。点击一个控件,键盘弹出,这时能看见第二个输入控件的情况下,点击第二个输入控件。页面没有自动增长以避免键盘遮挡。
将你demo中的两个输入控件调一下位置:点击一个输入控件后还能点第二个输入控件,这种情况下bug复现

导航栏也向上移动

问题已解决,谢谢了。对于基础差的人来说,注释的没有,用法的可以在说的清楚些。绝对没有指责的意思哈。感谢你的付出

影响导航栏

img_1648

当进行键盘处理后 ,当前view默认从导航栏下方开始,不是从屏幕上方(0,0)开始,

bug

输入文字后切换textField,文字会出现跳到动画!!!!!!!

回弹的高度不是键盘的高度而是使用了适应控件的原始坐标

issue description

situation:

我想实现类似于微信一类的输入框,键盘粘着输入控件,控件的大小随着输入的文字增加而增加。

issue:

似乎回弹的高度不是键盘的高度而是使用了适应控件的原始坐标。另外的建议是,MARGIN_KEYBOARD_DEFAULT只作为默认边距参数,暴露一个可以修改边距的属性?

是否支持uitextview

请问是否支持UITextView,并且在编辑时候,可以自动保证当前编辑行不被遮挡?

调用的时候要写一大块代码,简单处理遮挡问题可以加宏简化代码

在 ZYKeyboardUtil.h 中加入宏:
#define WeakSelf __weak typeof(self) weakSelf = self
#define KeyboardUtilHelper(obj,topMargin,...) obj = [[ZYKeyboardUtil alloc] initWithKeyboardTopMargin:topMargin];
WeakSelf;
[obj setAnimateWhenKeyboardAppearAutomaticAnimBlock:^(ZYKeyboardUtil *keyboardUtil) {
[keyboardUtil adaptiveViewHandleWithController:weakSelf adaptiveView:VA_ARGS];
}]

调用方法:
KeyboardUtilHelper(_keyboardUtil,10,weakSelf.text1, weakSelf.text2,weakSelf.text3,nil);

(不知道这样写有没有什么问题?)

循环引用问题

退出ViewController后,_keyboardUtil并没有被销毁,其他有键盘的也会受动画影响。

无法用pod安装

[!] Unable to satisfy the following requirements:

  • ZYKeyboardUtil (~> 0.4.1) required by Podfile

Specs satisfying the ZYKeyboardUtil (~> 0.4.1) dependency were found, but they required a higher minimum deployment target.

这是错误提示,求解

一个小bug

我弹出键盘,有个小黑条,而且整个APP的动画效果都受到了影响
img_1313

一个视图中多个textField如何使用呢?

[_keyboardUtil setAnimateWhenKeyboardAppearAutomaticAnimBlock:^NSDictionary *{
NSDictionary *adaptiveDict = [NSDictionary dictionaryWithObjectsAndKeys:weakSelf.mainTextField, ADAPTIVE_VIEW, weakSelf.view, CONTROLLER_VIEW, nil];
return adaptiveDict;
}];

bugly上的崩溃 can't start iterating in the middle of an iteration

#1416 NSInternalInconsistencyException
can't start iterating in the middle of an iteration

没找到解决办法,崩溃栈如下,请作者看看

`

CoreFoundation ___exceptionPreprocess + 124
1 libobjc.A.dylib objc_exception_throw + 56
2 CoreFoundation +[NSException raise:format:]
3 Foundation -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
4 FrontBoardServices 0x0000000188ef1000 + 144256
5 UIKit ___70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 120
6 UIKit -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 888
7 UIKit -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 464
8 FrontBoardServices 0x0000000188ef1000 + 52692
9 FrontBoardServices 0x0000000188ef1000 + 239916
10 FrontBoardServices 0x0000000188ef1000 + 239512
11 FrontBoardServices 0x0000000188ef1000 + 77912
12 UIKit -[UIApplication _synchronizeSystemAnimationFencesWithSpinCleanUpBlock:] + 572
13 UIKit ___realPreCommitHandler_block_invoke + 416
14 QuartzCore 0x000000018a599000 + 720400
15 QuartzCore 0x000000018a599000 + 554180
16 QuartzCore 0x000000018a599000 + 715368
17 UIKit +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 636
18 UIKit +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:completion:] + 100
**19 TuGeLe2016 -[ZYKeyboardUtil setKeyboardInfo:] (ZYKeyboardUtil.m:186)
20 TuGeLe2016 -[ZYKeyboardUtil handleKeyboard:keyboardAction:] (ZYKeyboardUtil.m:286)**
21 CoreFoundation _CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 20
22 CoreFoundation __CFXRegistrationPost + 400
23 CoreFoundation ____CFXNotificationPost_block_invoke + 60
24 CoreFoundation -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1504
25 CoreFoundation _CFXNotificationPost + 376
26 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
27 UIKit -[UIInputWindowController postStartNotifications:withInfo:] + 400
28 UIKit ___77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.907+ 388
29 UIKit +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 636
30 UIKit +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:]+ 128
31 UIKit -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1368
32 UIKit -[UIInputWindowController setPlacementChangeDisabled:withPlacement:] + 96
33 UIKit -[UIInputWindowController performOperations:withAnimationStyle:] + 56
34 UIKit ___80-[UIPeripheralHost(UIKitInternal) performMultipleOperations:withAnimationStyle:]_block_invoke +144
35 UIKit -[_UIRemoteKeyboards performOnControllers:] + 308
36 UIKit -[UIPeripheralHost(UIKitInternal) performMultipleOperations:withAnimationStyle:] + 136
37 UIKit -[UIPeripheralHost(UIKitInternal) setDeactivatedKeyboard:] + 372
38 UIKit -[UIApplication _deactivateForReason:notify:] + 96
39 UIKit ___61-[UIApplication _sceneSettingsPreLifecycleEventDiffInspector]_block_invoke + 124
40 FrontBoardServices 0x0000000188ef1000 + 144928
41 Foundation ___NSIndexSetEnumerate + 724
42 BaseBoard 0x0000000188e5b000 + 212840
43 FrontBoardServices 0x0000000188ef1000 + 120760
44 FrontBoardServices 0x0000000188ef1000 + 144380
45 UIKit ___70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 120
46 UIKit -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 888
47 UIKit -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 464
48 FrontBoardServices 0x0000000188ef1000 + 52692
49 FrontBoardServices 0x0000000188ef1000 + 239916
50 FrontBoardServices 0x0000000188ef1000 + 239512
51 FrontBoardServices 0x0000000188ef1000 + 240448
52 CoreFoundation _CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
53 CoreFoundation ___CFRunLoopDoSources0 + 524
54 CoreFoundation ___CFRunLoopRun + 804
55 CoreFoundation CFRunLoopRunSpecific + 444
56 GraphicsServices GSEventRunModal + 180
57 UIKit -[UIApplication _run] + 684
58 UIKit UIApplicationMain + 208
59 TuGeLe2016 main (main.m:17)
60 libdyld.dylib _start + 4

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.