[IQKeyboardManager sharedManager].enable = YES;[IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;for (int i = 0; i < 10; i++) { UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(100, i * 50 + 100, 200, 30)]; text.layer.borderColor = [UIColor grayColor].CGColor; text.layer.borderWidth = 1.0f; text.placeholder = [NSString stringWithFormat:@"%d", i]; [self.view addSubview:text];}复制代码
也许你的页面就是这样设置的,那么问题来了,当你的控制器是一个导航控制器的时候也许你会出现这样的问题
当你搜答案的时候可能有人建议你将view改成scrollView或者改成tableView就可以了
但是真的是这样吗,看下效果咯
[IQKeyboardManager sharedManager].enable = YES;[IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES; UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds]; scroll.contentSize = CGSizeMake(100, 300); [self.view addSubview:scroll]; for (int i = 0; i < 10; i++) { UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(100, i * 50 + 100, 200, 30)]; text.layer.borderColor = [UIColor grayColor].CGColor; text.layer.borderWidth = 1.0f; text.placeholder = [NSString stringWithFormat:@"%d", i]; [scroll addSubview:text];}复制代码
事实胜于雄辩,导航栏确实没问题了,但是新问题出来了,keyboard不好用了,怎么办,再从网上找解决方案实在是找不到了,那怎么办......最后的办法了,看Demo,其实这是最好使的办法,只不过自己有点懒(默默无语一分钟^_^)
其实人家IQ很高,早就考虑到这种情况了,只是我们没用心看罢了~ ~ ~ ~ 将scroll.scrollEnabled = NO;调试一下吧,完美解决.奖励自己一朵小花(得意脸)?? 最后祝大家工作顺利,代码没bug!!!!###再次回来了(ㄒoㄒ)因为项目需要的表格总数比较多,scrollView禁止滚动后下面表格没办法填了,所以scrollViewEnable不能为NO 这样就和前面说的解决方案冲突,那怎么办呢,经过我一番努力和不断探索终于发现了一个办法,只是当时的一个灵感(灵感真是个好东西)话不多说,上代码
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];scroll.contentSize = CGSizeMake(100, 800);[self.view addSubview:scroll];self.views = [NSMutableArray array];[IQKeyboardManager sharedManager].enable = YES;[IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;for (int i = 0; i < 15; i++) { UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(100, i * 50 , 200, 30)]; text.layer.borderColor = [UIColor grayColor].CGColor; text.layer.borderWidth = 1.0f; text.placeholder = [NSString stringWithFormat:@"%d", i]; [scroll addSubview:text]; [self.views addObject:text]; if (i == 0) { self.textField = text; }}复制代码
其实只是单纯的改了一下scrollView的contentSize比屏幕大就可以了