您的位置:首页 > 其它

输入框被键盘遮挡问题

2015-09-06 20:21 357 查看

//开始编辑输入框的时候,软键盘出现,执行此事件

-(void)textFieldDidBeginEditing:(UITextField *)textField{

CGRect frame = textField.frame;

int offset = frame.origin.y + 100 - (Height - 360.0);//键盘高度

NSTimeInterval animationDuration = 0.30f;

[UIView beginAnimations:@"ResizeForKeyboard" context:nil];

[UIView setAnimationDuration:animationDuration];

//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示

if(offset > 0){

self.view.frame = CGRectMake(0.0f, -offset, Width, Height);


[UIView commitAnimations];

}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{//触摸隐藏键盘

[self.view endEditing:YES];

[super touchesBegan:touches withEvent:event];

}



-(BOOL)textFieldShouldReturn:(UITextField *)textField {//按“完成”隐藏键盘

[textField resignFirstResponder];//隐藏输入键盘

return YES;

}



//输入框编辑完成以后,将视图恢复到原始状态

-(void)textFieldDidEndEditing:(UITextField *)textField{

self.view.frame =CGRectMake(0, 0, Width, Height);



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: