我有2个textview,一个在顶部,另一个在底部。当我试图在底部文字时写一些东西键盘即将出现在屏幕上,我无法看到我正在输入的内容。
如何在textview下面键入时键盘不可见或放置在完美的位置?
答案 0 :(得分:3)
- (void)textViewDidBeginEditing:(UITextView *)textView {
if (textView == bottomTextView) {
CGRect frame = self.view.frame;
frame.origin.y -= 250;
self.view.frame = frame;
}
}
- (void)textViewDidEndEditing:(UITextView *)textView {
if (textView == bottomTextView) {
CGRect frame = self.view.frame;
frame.origin.y += 250;
self.view.frame = frame;
}
}
您可以修改此250
值。
答案 1 :(得分:2)
答案 2 :(得分:1)
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == txtUserName) {
[txtUserName becomeFirstResponder];
[scrollView setContentOffset:CGPointMake(0,45) animated:YES];
} else if (textField == txtPassword) {
[txtPassword becomeFirstResponder];
[scrollView setContentOffset:CGPointMake(0,105) animated:YES];
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[scrollView setContentOffset:CGPointMake(0,0) animated:YES];
return YES;
}