求助,请问输入法弹出时,视图向上弹是怎么做的?
如题,就好像飞信iPhone客户端的登陆界面那样,当光标聚焦点在输入框的时候,输入法弹出,然后登陆界面整个视图就往上弹,所以,输入法就没有遮住要输入的文本框。请教下论坛里的大神们,这个是怎么做的?我拉了一个文本框在视图的下面,输入法一弹出来就遮住了,求教下大家,怎么能够不让它遮住。。。
[解决办法]
- (void)textFieldDidBeginEditingUITextField *)textField
{
[self animateTextField: textField up: YES];
}
- (void)textFieldDidEndEditingUITextField *)textField
{
[self animateTextField: textField up: NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 80; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
[解决办法]
简单的一句话说,调整view的frame
[解决办法]
我也经常遇到这种情况呢,我一般是用的ScrollView,想移多少就移多少
[scrollView setContentSize:CGSizeMake(x, y)];
(x, y)为移动到的坐标点
只需用Editing Did Begin来触发就可以了