相信大家都會(huì)遇到在工程中有輸入框,而鍵盤彈起時(shí)會(huì)被遮擋的情況从隆,在這里給大家介紹一個(gè)用動(dòng)畫的方法使頁(yè)面上移诚撵,直接上代碼:
#pragma mark - 屏幕上彈
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
//鍵盤高度216
if (textField == _verificationCodeTextField.myTextField || textField == _registationTextField.myTextField) {
//滑動(dòng)效果(動(dòng)畫)
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//將視圖的Y坐標(biāo)向上移動(dòng),以使下面騰出地方用于軟鍵盤的顯示
self.frame = CGRectMake(0.0f, -208.f, self.frame.size.width, self.frame.size.height);//64-216
[UIView commitAnimations];
}
}
#pragma mark -屏幕恢復(fù)
-(void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == _verificationCodeTextField.myTextField || textField == _registationTextField.myTextField) {
//滑動(dòng)效果
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//恢復(fù)屏幕
self.frame = CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height);//64-216
[UIView commitAnimations];
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者