【发布时间】:2014-11-17 11:35:22
【问题描述】:
我使用下面的代码来获取键盘高度,它在带有 ios8 的 iPhone 5s 设备中与带有 ios7 的 iPhone4s 设备中有所不同。因此,当我在带有 ios8 的 iPhone5s 中点击它时,我的文本字段移动得非常高,而相同的代码工作在带有 ios7 的 iPhone 4s 中很好。有人可以指导如何在两个版本中解决问题。
- (void)keyboardWasShown:(NSNotification*)notification
{
NSDictionary* info = [notification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
float kbHeight;
if (([UIApplication sharedApplication].statusBarOrientation== UIDeviceOrientationPortraitUpsideDown)||([UIApplication sharedApplication].statusBarOrientation== UIDeviceOrientationPortrait))
{
kbHeight=kbSize.height;
}
else
{
kbHeight=kbSize.width;
}
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbHeight, 0.0);
self.scroll.contentInset = contentInsets;
self.scroll.scrollIndicatorInsets = contentInsets;
CGRect rect = self.view.frame;
rect.size.height -= (kbHeight);
if (!CGRectContainsPoint(rect, self.activeField.frame.origin))
{
CGPoint scrollPoint = CGPointMake(0.0, self.activeField.frame.origin.y - ((kbHeight) - self.activeField.frame.size.height));
[self.scroll setContentOffset:scrollPoint animated:NO];
}
}
【问题讨论】:
-
问题是什么?
-
@Legoless 我认为问题是“有人可以帮助我吗?” :)
-
是的,因为键盘高度不同,我的应用程序面临一些问题..我怎样才能获得键盘的实际高度