开发者

How to hide keybord while typing in iphone app

开发者 https://www.devze.com 2023-03-23 12:07 出处:网络
I have 2 textview one is on top and other is at bottom. When I am trying to write something on bottom textview keyboard is coming on screen and I am not able to see what I am typing.

I have 2 textview one is on top and other is at bottom. When I am trying to write something on bottom textview keyboard is coming on screen and I am not able to see what I am typing.

How to make keyboard invisible or placed on perfect place while typing b开发者_如何学JAVAelow textview?


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

You can modify this 250 value.


The Answer to your problem lies here buddy..

Sliding UITextFeilds when keyboard appears

Its Best solution available.


Write This Delegate Methods For 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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消