我遇到了类似的问题 - 当键盘出现时,文本字段从屏幕顶部飞出!
似乎在 iOS8.0 中,与 iOS 7.0.3 相比,键盘尺寸发生了翻转。这是我的 iPad 应用程序的一些输出,它在横向(仅在横向)中运行:
iOS 7.0.3:
<0x7c4b4600 EditSignViewController.m:(1060)> the text fieldis <UITextField: 0x7b2dbd10; frame = (611 473; 90 30); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7b2dc850>; layer = <CALayer: 0x7b2dbe50>>
<0x83174f10 MasterSignFilterViewController.m:(461)> kbsize is {352, 1024}
<0x83174f10 MasterSignFilterViewController.m:(462)> kbsize.height is: 1024.000000
<0x83174f10 MasterSignFilterViewController.m:(463)> kbsize.width is: 352.000000
这是相同的输出,但运行的是 iOS 8:
<0x7d96d000 EditSignViewController.m:(1060)> the text fieldis <UITextField: 0x80af8c40; frame = (611 473; 90 30); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x851ab520>; layer = <CALayer: 0x80af8d80>>
<0x7c570f20 MasterSignFilterViewController.m:(422)> kbsize is {1024, 352}
<0x7c570f20 MasterSignFilterViewController.m:(423)> kbsize.height is: 352.000000
<0x7c570f20 MasterSignFilterViewController.m:(424)> kbsize.width is: 1024.000000`
在我看来,当设备旋转时,键盘尺寸坐标现在在 iOS 8 中旋转,而在 iOS 7 中它是静态的...
我做了一个快速测试 - MasterDetail iPad 应用程序,带有文本字段的 Scrollview,注册 KB 通知并在 KB 出现在屏幕上时吐出一些详细信息。
相关代码:
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSLog(@"KB coming up!");
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSLog(@"kbsize is %@", NSStringFromCGSize(kbSize));
NSLog(@"kbsize.height is: %f", kbSize.height);
NSLog(@"kbsize.width is: %f", kbSize.width);
}
看起来 iOS 8 KB 有点高(由于显示了预测结果),现在当屏幕处于横向时会旋转它的尺寸:
8.0 横向
2014-09-25 11:32:45.511 BKTest[2788:223360] KB coming up!
2014-09-25 11:32:45.512 BKTest[2788:223360] kbsize is {1024, 391}
2014-09-25 11:32:45.512 BKTest[2788:223360] kbsize.height is: 391.000000
2014-09-25 11:32:45.512 BKTest[2788:223360] kbsize.width is: 1024.000000
7.0.3 横向
2014-09-25 11:34:43.677 BKTest[2891:70b] KB coming up!
2014-09-25 11:34:43.677 BKTest[2891:70b] kbsize is {352, 1024}
2014-09-25 11:34:43.677 BKTest[2891:70b] kbsize.height is: 1024.000000
2014-09-25 11:34:43.678 BKTest[2891:70b] kbsize.width is: 352.000000
iOS 8.0 纵向
2014-09-25 11:29:43.235 BKTest[2741:220963] KB coming up!
2014-09-25 11:29:43.237 BKTest[2741:220963] kbsize is {768, 303}
2014-09-25 11:29:43.238 BKTest[2741:220963] kbsize.height is: 303.000000
2014-09-25 11:29:43.238 BKTest[2741:220963] kbsize.width is: 768.000000
7.0.3 纵向
2014-09-25 11:34:19.796 BKTest[2891:70b] KB coming up!
2014-09-25 11:34:19.797 BKTest[2891:70b] kbsize is {768, 264}
2014-09-25 11:34:19.797 BKTest[2891:70b] kbsize.height is: 264.000000
2014-09-25 11:34:19.797 BKTest[2891:70b] kbsize.width is: 768.000000