如何在iphone应用程序中键入时隐藏键盘

时间:2011-07-26 10:38:54

标签: iphone

我有2个textview,一个在顶部,另一个在底部。当我试图在底部文字时写一些东西键盘即将出现在屏幕上,我无法看到我正在输入的内容。

如何在textview下面键入时键盘不可见或放置在完美的位置?

3 个答案:

答案 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)

你的问题的答案就在这里伙计......

Sliding UITextFeilds when keyboard appears

最佳解决方案。

答案 2 :(得分:1)

为TextField编写此委托方法

- (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;
}