相信大家都会遇到在工程中有输入框,而键盘弹起时会被遮挡的情况,在这里给大家介绍一个用动画的方法使页面上移,直接上代码:
#pragma mark - 屏幕上弹
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
//键盘高度216
if (textField == _verificationCodeTextField.myTextField || textField == _registationTextField.myTextField) {
//滑动效果(动画)
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
self.frame = CGRectMake(0.0f, -208.f, self.frame.size.width, self.frame.size.height);//64-216
[UIView commitAnimations];
}
}
#pragma mark -屏幕恢复
-(void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == _verificationCodeTextField.myTextField || textField == _registationTextField.myTextField) {
//滑动效果
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//恢复屏幕
self.frame = CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height);//64-216
[UIView commitAnimations];
}
}