在iOS 8之前,当向应用程序报告时,键盘的位置和宽度/高度总是与纵向相对。 (例如,Landscape的键盘宽度在y方向,在iPad上约为352像素。) 从iOS 8开始,已更新为始终在您的(物理)视图的左上角具有(0,0),宽度/高度反映了您通常在iOS以外期望的x/y方向。如果你以前通过keyboardDidShow
的[notification userInfo]
这样的东西定位你的键盘,你会得到一些不太合理的数字。您可以使用的东西沿着这些路线考虑到预iOS8上的特质:
- (void)keyboardDidShow: (NSNotification *) notification{
NSDictionary *keyboardInfo = [notification userInfo];
CGSize keyboardSize = [[keyboardInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
float height, width;
if(UIInterfaceOrientationIsPortrait(orientation)){
width = keyboardSize.width;
height = keyboardSize.height;
} else {
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1){
width = keyboardSize.height;
height = keyboardSize.width;
} else {
width = keyboardSize.width;
height = keyboardSize.height;
}
}
// Remainder of function
}
其中可重构下来......
- (void)keyboardDidShow: (NSNotification *) notification{
NSDictionary *keyboardInfo = [notification userInfo];
CGSize keyboardSize = [[keyboardInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
float width = keyboardSize.width;
float height = keyboardSize.height;
if(!UIInterfaceOrientationIsPortrait(orientation) && (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1)){
width = keyboardSize.height;
height = keyboardSize.width;
}
// Remainder of function
}
此外,8.1更新修正了几个景观/旋转错误可能与上述更改有关。抓住更新,看看是否解决了你的问题。
我在想这可能是一个iPhone 6的错误。 – MobileDev98 2014-10-09 01:08:24