Am using the below code to get keyboard height which varies in IPhone 5s device with ios8 compared to IPhone4s device with ios7 .As a result my textfield is moving very high when i tap on it in IPhone5s with ios8 while the same code works fine in IPhone 4s with ios7.Can someone guide how the problem can be fixed in both versions.
- (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];
}
}