您的位置:首页 > 移动开发 > IOS开发

iOS解决键盘遮挡TextFiled的问题

2013-07-31 13:41 441 查看
//UITextField的协议方法,当开始编辑时监听-(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;//上移30个单位,按实际情况设置CGRect rect=CGRectMake(0.0f,-70,width,height);self.view.frame=rect;[UIView commitAnimations];return YES;}//恢复原始视图位置-(void)resumeView{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;//如果当前View是父视图,则Y为20个像素高度,如果当前View为其他View的子视图,则动态调节Y的高度float Y = 0.0f;CGRect rect=CGRectMake(0.0f,Y,width,height);self.view.frame=rect;[UIView commitAnimations];}

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