最近项目中使用到了IQKeyboardManager
把使用的一些方法做一下简单的介绍,干货都在下面,开撸
Githup地址
1 AppDelegate里倒入头文件即可使用,
#import <IQKeyboardManager/IQKeyboardManager.h>
2.某个界面不使用IQKeyboardManager
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[IQKeyboardManager sharedManager].enable = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[IQKeyboardManager sharedManager].enable = YES;
}
3.工具条消失
屏幕快照 2017-06-06 下午5.12.46.png[IQKeyboardManager sharedManager].enableAutoToolbar = NO;
4 return键改为next ,最后一个textfield变为 return
#import <IQKeyboardReturnKeyHandler.h>
//声明一个变量
@interface ViewController ()
{
IQKeyboardReturnKeyHandler *returnKeyHandler;
}
@end
//在viewDidLoad中写入
returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
//这样键盘return会变成Next,只有当时最后一个时会变成return
5.点击空白处 键盘隐藏
[IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
6 键盘弹起,视图上移 UINavgationBar消失
1使用 storyboard 或者 xib
只需将view的Class 换成 UIScrollView
屏幕快照 2017-06-06 下午5.21.05.png
这时候你会发现,What is the Fuck? 视图全他妈乱了,莫慌莫慌,
只需要给scrollview中的某一个view拉入一条相对scrollview的约束:Center Horizontally in Container
2 代码需要覆盖UIViewController中的-(void)loadView方法:
-(void)loadView
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = scrollView;
}
7修改工具条上右侧的Done按钮
//设置为文字
[IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = @"完成";
//设置为图片
[IQKeyboardManager sharedManager].toolbarDoneBarButtonItemImage = [UIImage imageNamed:@"imageName"];
8.修改工具条上字体的颜色
[IQKeyboardManager sharedManager].shouldToolbarUsesTextFieldTintColor = NO;
[IQKeyboardManager sharedManager].toolbarTintColor = [UIColor brownColor];
9.设置输入框与工具条的间距,默认为10.0f
[IQKeyboardManager sharedManager].keyboardDistanceFromTextField = 0.0f;
网友评论