IQKeyBoardManager遇到的坑
2017-12-02 本文已影响0人
差一点不是帅哥
一般我们都会在入口类直接集成IQKeyBoardManager,方便项目中管理键盘和别的一些操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
manager.enable = YES;
manager.shouldResignOnTouchOutside = YES;
manager.shouldToolbarUsesTextFieldTintColor = YES;
manager.enableAutoToolbar = NO;
}
IQKeyBoardManager 使用的界面,当键盘弹出后,在键盘没有收回的时候弹出UIAlertView 或者使用UIAlertController,或者textField输入的时候,这样之后点击界面就会出现界面漂移现象。
解决办法;进入控制器的时候关闭这个框架,出这个界面开启这个框架。如下代码
//视图控制器已经加载完成之后,禁用IQKeyboardManager
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[IQKeyboardManager sharedManager] setEnable:NO];
}
//视图控制器已经消失,开启IQKeyboardManager
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[IQKeyboardManager sharedManager] setEnable:YES];
}