UITextField和UITextView被键盘遮住的处理办法

来源:互联网 发布:jsp连接sql server2005 编辑:程序博客网 时间:2024/05/19 22:54

- (void)textFieldDidBeginEditing:(UITextField *)textField  

{  

    float offset = 0.0f;  

    if(self.txtField == textField)  

    {  

        offset = - 180.0f;  

    }  

    NSTimeInterval animationDuration = 0.30f;  

    [UIView beginAnimations:@"ResizeForKeyBoard"context:nil];  

    [UIView setAnimationDuration:animationDuration];  

    float width = self.view.frame.size.width;  

    float height = self.view.frame.size.height;  

    CGRect rect = CGRectMake(0.0f, offset , width, height);  

    self.view.frame = rect;  

    [UIView  commitAnimations];  

}  

- (void)textFieldDidEndEditing:(UITextField *)textField

{

    float offset = 0.0f;  

   

    NSTimeInterval animationDuration = 0.30f;  

    [UIView beginAnimations:@"ResizeForKeyBoard"context:nil];  

    [UIView setAnimationDuration:animationDuration];  

    float width = self.view.frame.size.width;  

    float height = self.view.frame.size.height;  

    CGRect rect = CGRectMake(0.0f, offset , width, height);  

    self.view.frame = rect;  

    [UIView commitAnimations];  

}

以上是textfeild得处理方法。textview用textViewDidBeginEditing和textViewDidEndEditing。
0 0
原创粉丝点击