1、弹起 整个视图向上移动
在viewdidload中添加代理
_username.delegate =self;
_password.delegate = self;
2、添加弹出方法
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSTimeInterval animationDuration=0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
//上移n个单位,按实际情况设置
CGRect rect=CGRectMake(0.0f,-130,width,height);
self.view.frame=rect;
[UIView commitAnimations];
return YES;
}
3、添加点击手势
UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
tap1.cancelsTouchesInView = NO;