一。在普通的View界面
1.当点击输入框,弹出键盘挡住输入框,可用增加页面高度,调整坐标。其中count = 0的操作看具体需求。
- (void)textFieldDidBeginEditing:(UITextField *)textField
{ //当点触textField内部,开始编辑都会调用这个方法。textField将成为first responder
if(count == 0){
//当出现键盘时,添加frame的高度,已便键盘的使用
NSTimeInterval animationDuration = 0.30f;
CGRect frame = self.view.frame;
frame.origin.y -=130;
frame.size.height +=130;
self.view.frame = frame;
[UIView beginAnimations:@"ResizeView" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
count++;
}
}
2.关闭键盘,点击背景出发 touchesBegan事件,通过取消输入框第一响应来关闭键盘,并将页面高度和坐标还原。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if (![touch.view isKindOfClass:[UITextField class]]) {
[self.loginText resignFirstResponder];
[self.pwdText resignFirstResponder];
}
if(count != 0){
NSTimeInterval anima