【发布时间】:2014-11-25 07:09:59
【问题描述】:
我有一个 UITextView 覆盖故事板中的整个视图控制器设置。顶部布局指南、底部布局指南、前导边距和后边距都有限制。
我已注册到键盘通知以调整内容插入,如下所示:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardAppeared:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDisappeared:)
name:UIKeyboardDidHideNotification
object:nil];
keyboardAppeared 的实现:
- (void)keyboardAppeared:(NSNotification *)notification {
NSDictionary *notificationUserInfo = [notification userInfo];
CGRect keyboardRect = [[notificationUserInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
self.textView.contentInsets = UIEdgeInsetsMake(0, 0, keyboardRect.heignt, 0);
self.textView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, keyboardRect.height, 0);
}
keyboardDisappeared 的实现:
- (void)keyboardDisappeared:(NSNotification *) {
self.textView.contentInsets = UIEdgeInsetsZero;
self.textView.scrollIndicatorInsets = UIEdgeInsetsZero;
}
这里的问题是当出现键盘时,如果 textView 文本较少,则 textView 中会出现不需要的滚动。当文本大小超过 textView 高度时,不会出现不需要的滚动。
请帮忙!
【问题讨论】:
-
链接没有帮助。我在文本末尾得到了额外的空间。我已经自动将AdjustScrollViewInsets 切换为NO。
标签: ios uitextview uikeyboard