http://www.devdiv.com/thread-70159-1-1.html
实现以下三个方法,如果d出的键盘会遮住输入框 ,整体的界面会向上移动,这样就不会遮住输入框了。自己增加UITextFIEldDelegate委托。
只适合iPhone,如果想要支持iPad,只要把216改成iPad上面键盘的高度即可。
C代码 - (voID)keyboarDWillShow:(NSNotification *)noti { //键盘输入的界面调整 //键盘的高度 float height = 216.0; CGRect frame = self.vIEw.frame; frame.size = CGSizeMake(frame.size.wIDth, frame.size.height - height); [UIVIEw beginAnimations:@"Curl"context:nil];//动画开始 [UIVIEw setAnimationDuration:0.30]; [UIVIEw setAnimationDelegate:self]; [self.vIEw setFrame:frame]; [UIVIEw commitAnimations]; } - (@H_419_101@BOol)textFIEldShouldReturn:(UITextFIEld *)textFIEld // When the user presses return, take focus away from the text fIEld so that the keyboard is dismissed. NSTimeInterval animationDuration = 0.30f; [UIVIEw beginAnimations:@"ResizeforKeyboard" context:nil]; [UIVIEw setAnimationDuration:animationDuration]; CGRect rect = CGRectMake(0.0f, 0.0f, self.vIEw.frame.size.wIDth, self.vIEw.frame.size.height); self.vIEw.frame = rect; [UIVIEw commitAnimations]; [textFIEld resignFirstResponder]; return YES; - (voID)textFIEldDIDBeginEditing:(UITextFIEld *)textFIEld CGRect frame = textFIEld.frame; int offset = frame.origin.y + 32 - (self.vIEw.frame.size.height - 216.0);//键盘高度216 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; if(offset > 0) { CGRect rect = CGRectMake(0.0f, -offset,wIDth,height); self.vIEw.frame = rect; } [UIVIEw commitAnimations]; }
以下转自 http://janedoneway.iteye.com/blog/1575250
另外我自己做了一点修改: 在实际用的时候,键盘消失原来的控件并没有回归都原来的位置,而是上移了20个像素,我估计是因为顶部bar的原因,只要将22行代码改成如下就可以了: CGRect rect = CGRectMake(0.0f,20.0f,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height); 总结以上是内存溢出为你收集整理的UITextField被键盘遮挡问题解决方法全部内容,希望文章能够帮你解决UITextField被键盘遮挡问题解决方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)