Search code examples
xcodeios7scrollios8keyboard

Xcode 5 and iOS 8 keyboard scroll not working


So to be to the point, when I build my project with Xcode 6, the components on my screen scroll up correctly when the keyboard is about to be shown.

However, when I build with Xcode 5, all components go off the screen (aka they move too high). I searched but I can't find the problem.

This problem only occurs on iOS 8 in landscape mode. On iOS 7 everything works just fine. Does anyone have an idea what the problem is? It is mandatory to build with Xcode 5 for some reasons. Thanks!

When the view is created

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShown:) name:UIKeyboardWillShowNotification object:nil];

Event Handler

- (void)keyboardShown:(NSNotification *)notification{
    CGSize kbSize = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    float kbHeight = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? kbSize.height : kbSize.width;
    if( [[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) kbHeight = kbSize.height;

    _origScrollIndicatorInsets = _legsTableView.scrollIndicatorInsets;
    _origContentInset = _legsTableView.contentInset;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbHeight, 0.0);
    _legsTableView.contentInset = contentInsets;
    _legsTableView.scrollIndicatorInsets = contentInsets;

    if (_activeTextField) {
        CGRect fieldRect = [_legsTableView convertRect:_activeTextField.bounds fromView:_activeTextField];
        [_legsTableView scrollRectToVisible:fieldRect animated:YES];
    }
}

Solution

  • From this post I've found my answer for calculation the height and this works perfectly. keyboard height varies in ios8

    - (void)keyboardWillShow:(NSNotification*)note {
          NSDictionary* info = [note userInfo];
          CGSize _kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
          float kbHeight = _kbSize.width > _kbSize.height ? _kbSize.height : _kbSize.width;
    }