IQKeyboardManager在项目中使用的注意
2020-06-09 本文已影响0人
里克尔梅西
一、常规用法
AppDelegate里倒入头文件即可使用
#import <IQKeyboardManager/IQKeyboardManager.h>
IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
//控制整个功能是否启用。
manager.enable = YES;
//控制点击背景是否收起键盘
manager.shouldResignOnTouchOutside = YES;
//控制键盘上的工具条文字颜色是否用户自定义。 注意这个颜色是指textfile的tintcolor
manager.shouldToolbarUsesTextFieldTintColor = YES;
//中间位置是否显示占位文字
manager.shouldShowTextFieldPlaceholder = YES;
//设置占位文字的字体
manager.placeholderFont = [UIFont boldSystemFontOfSize:17];
//控制是否显示键盘上的工具条。
manager.enableAutoToolbar = YES;
//某个类中禁止使用工具条
[[IQKeyboardManager sharedManager]disableToolbarInViewControllerClass:[UIViewController class]];
二、某个页面禁止使用
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
keyboardManager.enable = NO;
keyboardManager.enableAutoToolbar = NO;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
keyboardManager.enable = YES;
keyboardManager.enableAutoToolbar = YES;
}
三、设置偏移距离,比如不遮挡登录按钮
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[IQKeyboardManager sharedManager]setKeyboardDistanceFromTextField:60];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[IQKeyboardManager sharedManager]setKeyboardDistanceFromTextField:10];
}
参考:https://www.jianshu.com/p/46973f993824
https://www.jianshu.com/p/a3e4ec21c168