IQKeyboardManager Github地址

经常在开发一个应用程序,我们遇到了一个问题,iPhone的键盘上滑覆盖的UITextField / UITextViewIQKeyboardManager可以防止键盘滑动问题和覆盖UITextField / UITextView无需你输入任何代码,不需要额外的设置要求。使用IQKeyboardManager你只需要添加源文件到你的项目。

主要特点

1)无代码 
2)自动工作 
3)没有更多的UIScrollView
4)没有更多的子类 
5)没有更多的手动工作 
6)没有更多#imports

截图


IQKeyboardManager 支持 CocoaPods

pod ‘IQKeyboardManager’

管理

UINavigationBar

如果你不使用storyboardxib创造你的视图。你需要重写-(void)UIViewController loadview方法,需要设置一个UIScrollView实例self.view

  1. -(void)loadView

  2. { 

  3. UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

  4. self.view = scrollView;

  5. }

为某一个ViewController禁用IQKeyboardManager

如果你想在某个 viewcontroller 禁用 IQKeyboardManager 你应该在 ViewDidAppear 中禁用IQKeyboardManager,而在ViewWillDisappear启用它 
代码:

  1. #import "IQKeyboardManager.h" @implementationExampleViewController  BOOL _wasKeyboardManagerEnabled; }
  2. -(void)viewDidAppear:(BOOL)animated
  3. {
  4. [super viewDidAppear:animated];
  5. _wasKeyboardManagerEnabled = [[IQKeyboardManager sharedManager] isEnabled];
  6. [[IQKeyboardManager sharedManager] setEnable:NO];
  7. }
  8. -(void)viewWillDisappear:(BOOL)animated
  9. {
  10. [super viewWillDisappear:animated];
  11. [[IQKeyboardManager sharedManager] setEnable:_wasKeyboardManagerEnabled]; }  @end

键盘的回车键处理

1)创建一个实例变量实例化IQKeyboardReturnKeyHandler 在 ViewController 的 viewDidLoad 中

代码:

  1. @implementationViewController  { IQKeyboardReturnKeyHandler *returnKeyHandler;
  2. }
  3. - (void)viewDidLoad
  4. {
  5. [super viewDidLoad];
  6. returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
  7. }

改变键盘上的返回键。

设置实例变量为零的dealloc方法
  1. -(void)dealloc {
  2. returnKeyHandler = nil;
  3. }

UIToolbar(IQToolbar)

1)如果你不想添加一个特定的自动工具栏在键盘上方,应该添加一个类作为它的工具栏
  1. textField.inputAccessoryView = [[UIView alloc] init];
2)如果你需要自己控制上/下/完成按钮,那么应该使用UIView类的方法,创建你的文本框工具栏。

代码:

  1. -(void)viewDidLoad
  2. {
  3.  
  4. [super viewDidLoad];    //Adding done button for textField1  [textField1 addDoneOnKeyboardWithTarget:self action:@selector(doneAction:)];    //Adding previous/next/done button for textField2  [textField2 addPreviousNextDoneOnKeyboardWithTarget:self previousAction:@selector(previousAction:) nextAction:@selector(nextAction:) doneAction:@selector(doneAction:)];  //Adding cancel/done button for textField3  [textField3 addCancelDoneOnKeyboardWithTarget:self cancelAction:@selector(cancelAction:) doneAction:@selector(doneAction:)]; /*! previousAction. */  -(void)previousAction:(id)button //previousAction  /*! nextAction. */  -(void)nextAction:(id)button //nextAction  /*! doneAction. */  -(void)doneAction:(UIBarButtonItem*)barButton //doneAction  /*! cancelAction. */  -(void)cancelAction:(UIBarButtonItem*)barButton //cancelAction  }

功能和使用

UIKeyboard 处理
  1. +(instancetype)sharedManager : Returns the default singleton instance.
  2. @property BOOL enable : Use this to enable/disable managing distance between keyboard & textField/textView).
  3. @property CGFloat keyboardDistanceFromTextField : Set Distance between keyboard & textField. Can't be less than zero. Defaultis10.@property BOOL preventShowingBottomBlankSpace : Prevent to show bottom blanck area when keyboard slide up the view.
IQToolbar处理
  1. @property BOOL enableAutoToolbar : Enable autoToolbar behaviour. If It is set to NO. You have to manually create UIToolbar for keyboard. Defaultis YES.
  2. @property IQAutoToolbarManageBehaviour toolbarManageBehaviour : Setting toolbar behaviour to IQAutoToolbarBySubviews to manage previous/next according to UITextField's hierarchy in it's SuperView. Set it to IQAutoToolbarByTag to manage previous/next according to UITextField's tag propertyin increasing order. Defaultis IQAutoToolbarBySubviews.
  3. @property BOOL shouldToolbarUsesTextFieldTintColor : If YES, then uses textField's tintColor propertyfor IQToolbar, otherwise tintColor is black. Defaultis NO.
  4. @property BOOL shouldShowTextFieldPlaceholder : If YES, then it add the textField's placeholder text on IQToolbar. Defaultis YES.
  5. @property UIFont *placeholderFont : placeholder Font. Defaultis nil. Defaultis YES.
UITextView处理
  1. @property BOOL canAdjustTextView : Giving permission to modify TextView's frame. Adjust textView's frame when it is too big in height. Defaultis NO.
  2. @property BOOL shouldFixTextViewClip : Adjust textView's contentInset to fix fix for iOS 7.0.x -(#Stackoverflow). Defaultis YES.
UIKeyboard 外观覆盖
  1. @property BOOL overrideKeyboardAppearance : Override the keyboardAppearance for all textField/textView. Defaultis NO.
  2. @property UIKeyboardAppearance keyboardAppearance : If overrideKeyboardAppearance is YES, then all the textField keyboardAppearance issetusing this property.
关闭UITextField/UITextView
  1. @propertyBOOL shouldResignOnTouchOutside : Resign textField if touched outside of UITextField/UITextView.
  2. -(void)resignFirstResponder : Resigns currently first responder field.
UISound处理
  1. @property BOOL shouldPlayInputClicks : If YES, then it plays inputClick sound onnext/previous/done click. Defaultis NO.
UIAnimation
  1. @property BOOL shouldAdoptDefaultKeyboardAnimation : If YES, thenuses keyboard default animation curve style to move view, otherwise uses UIViewAnimationOptionCurveEaseOut animation style. Defaultis YES.

特征

1)支持设备方向。 
2)启用/禁用键盘消息时,需要设置 enable 的布尔值。 
3)简单的集成。 
4)作为一个textField/textViewAutoHandle UIToolbar需要设置 enableAutoToolbar 的布尔值。 
5)可以由父视图AutoHandle UIToolbartextField/textView,使用toolbarManageBehaviour枚举。 
6)方便地添加上下和完成按钮键盘UIToolbar UIView类,自动使用enableAutoToolbar布尔值。 
7)启用/禁用,下/上一个按钮类的方法,自动使用enableAutoToolbar布尔值。 
8)键盘设置距离文本框使用keyboardDistanceFromTextField。 
9)键盘触摸外面用shouldResignOnTouchOutside. 禁用。 
10)管理的框架时,UITextView高度太大,使用canAdjustTextView 设置适合屏幕。 
11)适用在UITableView/UIScrollView 中的UITextField/UITextView
12)可以输入声音在点击“下/上一页/完成”时。

延伸阅读:

IQKeyboardManager 
      iOS自动处理键盘事件的第三方库:IQKeyboardManager

以上就介绍了iOS 键盘自适应(IQKeyboardManager)使用小结,包括了方面的内容,希望对IOS开发有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_117701.html

iOS 键盘自适应(IQKeyboardManager)使用小结的更多相关文章

  1. iOS 键盘框架IQKeyboardManager使用

    框架地址:https://github.com/hackiftekhar/IQKeyboardManager AppDelegate.m文件中   #import <IQKeyboardMana ...

  2. ios键盘弹起 body的高度拉长,页面底部空白问题。ios软键盘将页面抵到上面后,关闭软键盘页面不回弹的问题。

    js 监听ios手机键盘弹起和收起的事件 /* js 监听ios手机键盘弹起和收起的事件 */ document.body.addEventListener('focusin', () => { ...

  3. iOS开发小技巧--iOS键盘 inputView 和 inputAccessoryView

    iOS键盘 inputView 和 inputAccessoryView 1.inputAccessoryView UITextFields和UITextViews有一个inputAccessoryV ...

  4. WPF自适应窗体实现小结

    WPF自适应窗体实现小结 这几天,因工作需要,要对一个小软件进行UI调整.主要内容就是让其能够实现自适应窗体(包括文字和图标),做成像WIN7下的Media Center一样的UI.自适应窗体,顾名思 ...

  5. IOS - 键盘处理

    iOS 发布了很多关于屏幕上键盘的通知.下面列出了这些通知的简要解释: UIKeyboardWillShowNotification 当键盘即将要显示的时候将会发出这个通知.这个通知包含了用户信息库, ...

  6. IOS键盘弹出、隐藏

    IOS键盘 UIKeyboardFrameBeginUserInfoKey:动画开始前键盘的size UIKeyboardFrameEndUserInfoKey:动画结束后键盘的size - (voi ...

  7. iOS界面设计切图小结

    iOS界面设计切图小结 APR 12TH, 2013 1.基本尺寸 (1)界面 实际设计时按: iPhone4.4s:640px*960px iPhone5: 640px*1136px iPad:15 ...

  8. iOS键盘中英文切换键盘高度获取通知方法

    iOS键盘中英文切换键盘高度获取通知方法, 有需要的朋友可以参考下. 注册通知 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppea ...

  9. iOS 键盘遮挡输入框万能解决方案(多个输入框)

    效果图如下: 思路分析: 代码: 知识点: 问题: 效果图如下: 思路分析: 当我们有很多输入框时,有时候键盘弹出来会遮挡着输入框.我们需要获取输入框和键盘相对于最外层视图的位置来判断是否遮挡,如果遮 ...

随机推荐

  1. 【树形dp】VK Cup 2012 Round 1 D. Distance in Tree

    统计树中长度为K的路径条数. 用f[u][k]表示从u结点的子树中出发,终止于u结点的长度为k的路径条数. 边dp边统计答案.为了防止重复统计,在枚举子节点的时候,先将该子节点和当前u结点(和前面已经 ...

  2. 实验三 敏捷开发与XP实践实验报告

    实验三 敏捷开发与XP实践实验报告 实验内容 1. XP基础 2. XP核心实践 3. 相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vi ...

  3. redis源码解析之内存管理

    zmalloc.h的内容如下: void *zmalloc(size_t size); void *zcalloc(size_t size); void *zrealloc(void *ptr, si ...

  4. Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp

    D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...

  5. Java反射机制的简单学习

    今天看了一下Java的反射机制,就此记录一下. 首先,我们要先了解一下什么是反射? 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力. JAV ...

  6. centos yum命令报错

    Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Could not retriev ...

  7. node webkit (nw.js) 无法调试的结局方案之一

    之前做过nw项目,当时主要内容是由别人做的!过后回到家中,自己研究了下这方面.结果发现我自己写的nw 客户端不可以调试!在网上各种找办法,没找到,深感绝望,突然看到 (https://github.c ...

  8. 嵌入式学习之Nand Flash

    转:http://m.blog.csdn.net/blog/woshixiongge/9017149 Nand Flash是flash存储器的一种,其内部采用非线性宏单元模式,为固态大容量内存的实现提 ...

  9. jvm分析内存泄露

          首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 Java小组 工具资源 - 导航条 - 首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 Java小组 工具资源     ...

  10. 查看mysql服务器连接

    查看服务器连接,排查连接过多,查看连接状态时特别有用! 命令: show full processlist 作用: 显示当前运行的线程以及状态,也可以根据该命令来查看服务器状态. Id: 连接Id.U ...