如何防止在Xcode中禁用预测词/纠正?
我有一个Textfield,当键盘打开和关闭时它会上下移动,但当校正为Enabled / Disabled时,文本字段会跳转到视图的顶部。
我宁愿阻止预测文本被禁用,但如果不可能,我怎样才能阻止文本字段跳转到视图的顶部?
我有一个Outlet连接到文本字段的垂直空间 - 底部布局指南,如下所示:
property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewBottomConst;
以下是我的键盘willshow
和willhide
:
- (void)observeKeyboard {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification {
NSDictionary *info = [notification userInfo];
NSValue *kbFrame = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
NSTimeInterval animationDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect keyboardFrame = [kbFrame CGRectValue];
CGRect finalKeyboardFrame = [self.view convertRect:keyboardFrame fromView:self.view.window];
int kbHeight = finalKeyboardFrame.size.height;
int height = kbHeight + self.textViewBottomConst.constant;
self.textViewBottomConst.constant = height;
self.btnViewBottomConst.constant = height;
_tvChat.scrollEnabled = YES;
[_tvChat scrollRangeToVisible:_tvChat.selectedRange];
[UIView animateWithDuration:animationDuration animations:^{
[self.view layoutIfNeeded];
}];
}
- (void)keyboardWillHide:(NSNotification *)notification {
NSDictionary *info = [notification userInfo];
NSTimeInterval animationDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
self.textViewBottomConst.constant = 10;
self.btnViewBottomConst.constant = 10;
[_tvChat scrollRangeToVisible:_tvChat.selectedRange];
[UIView animateWithDuration:animationDuration animations:^{
[self.view layoutIfNeeded];
}];
}