textField或textviewz处理键盘弹出时遮住输入框的比较简捷得方法
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
float offset = 0.0f;
if(self.txt_name == textField)
{
offset = - 180.0f;
}
NSTimeInterval animationDuration = 0.30f;
[UIViewbeginAnimations:@"ResizeForKeyBoard"context:nil];
[UIViewsetAnimationDuration: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;
[UIViewcommitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
float offset = 0.0f;
NSTimeInterval animationDuration = 0.30f;
[UIViewbeginAnimations:@"ResizeForKeyBoard"context:nil];
[UIViewsetAnimationDuration: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;
[UIViewcommitAnimations];
}
以上是textfeild得处理方法。textview用textViewDidBeginEditing和textViewDidEndEditing。
浙公网安备 33010602011771号