本文介绍了iPad 中的键盘隐藏文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了键盘在 UIScrollView
中隐藏 UITextField
的问题.
Hi I had a problem that keyboard hiding UITextField
in UIScrollView
.
为此,我使用了苹果文档中的一些代码.
For that I used some code from apple documents.
在 ViewDidLoad
In ViewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
和
- (void)keyboardWasShown:(NSNotification*)aNotification
{
int rowNumber=(selectetTxtfld.tag-1)/7;
if (rowNumber>2) {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect bkgndRect = selectetTxtfld.superview.frame;
bkgndRect.size.height += kbSize.height;
[selectetTxtfld.superview setFrame:bkgndRect];
[scrlView setContentOffset:CGPointMake(0.0, selectetTxtfld.frame.origin.y-200) animated:YES];
}
}
和
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrlView.contentInset = contentInsets;
scrlView.scrollIndicatorInsets = contentInsets;
scrlView.contentOffset=CGPointZero;
}
现在一切正常.但我在代码行中听到了
now it is working fine.But I heard that in code line
[scrlView setContentOffset:CGPointMake(0.0, selectetTxtfld.frame.origin.y-200) animated:YES];
我使用的键盘高度为 200.如果我这样使用,苹果将拒绝该应用程序.对还是不对.
for the height of keyboard I am using 200.If I used like this the apple will reject the app. Is that right or not.
我也试过这个代码.但不显示 scrllview 的文本字段和内容
I tried this code also. But not showing the textfields and content of the scrllview
[scrlView setContentOffset:CGPointMake(0.0, selectetTxtfld.frame.origin.y-kbSize.height) animated:YES];
在我的应用中,我使用了方向
in my app I am using the orientation
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
所以请帮助我如何使用键盘高度.
So please help me how to use the key board height.
推荐答案
获取键盘尺寸:
- (void) keyboardWasShown:(NSNotification *)nsNotification {
NSDictionary *userInfo = [nsNotification userInfo];
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSLog(@"Height: %f Width: %f", kbSize.height, kbSize.width);
// Portrait: Height: 264.000000 Width: 768.000000
// Landscape: Height: 1024.000000 Width: 352.000000
}
这篇关于iPad 中的键盘隐藏文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!