解决问题方案:
1.方案一
设置UITextField的属性keyboardType
将其设置为UIKeyboardTypeASCIICapable;
第一次可能登录成功如果密码输入出错,登录失败,键盘设置为UIKeyboardTypeASCIICapable会失效。
所以,必须将登录按钮的方法中重现要设置密码框(UITextField类型)的属性keyboardType为UIKeyboardTypeASCIICapable。
2.方案二思想是是整个页面网上移动。
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- (void)keyboardWillShow:(NSNotification *)noti{
NSDictionary *info = [noti userInfo];
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
_keyBoardHeight = keyboardSize.height;
CGRect frame = _teltTextField.frame;
int offset = frame.origin.y - (KWIDTH - _keyBoardHeight);
NSTimeInterval animationDur = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDur];
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
if (offset > 0) {
self.view.frame = CGRectMake(0, -offset, self.view.frame.size.width, self.view.frame.size.height);
}
[UIView commitAnimations];
}
//当用户按下return键或者按回车键,keyboard消失
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
//输入框编辑完成以后,将视图恢复到原始状态.调用这个方法
-(void)textFieldDidEndEditing:(UITextField *)textField
下面的可视化 编程的代码例子。
- (IBAction)passwordEditDidend:(id)sender {
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}