TPKeyboardAvoiding icon indicating copy to clipboard operation
TPKeyboardAvoiding copied to clipboard

contentInset set to 0 in NavigationController provoking content to be under navigation bar

Open fabianz66 opened this issue 11 years ago • 3 comments

When working with a NavigationController in a storyboard with a rootView and a secondView (push segue) both with TPKeyboardAvoidingScrollView when you get to the secondView TPKeyboardAvoiding_keyboardWillShow [UIScrollView+TPKeyboardAvoidingAdditions] is still called in the rootView so it causes later for the rootView to be under the navigation bar as it sets its contentInset.top to 0.

I fixed it this way:

In TPKeyboardAvoiding_keyboardWillShow method from [UIScrollView+TPKeyboardAvoidingAdditions] :

Original code:

UIView *firstResponder = [self TPKeyboardAvoiding_findFirstResponderBeneathView:self];

Changed code:

UIView *firstResponder = [self TPKeyboardAvoiding_findFirstResponderBeneathView:self];
if(!firstResponder) {
        return;
}

fabianz66 avatar Aug 25 '14 02:08 fabianz66

thanks for this – worked like a charm for me in a similar situation. A UINavigationController containing viewControllers [A, B], where B is the top view controller, a text field in B was active, and then the back button was pushed. When popped back to A, the content offset was consistently being pushed -44 up, which let to annoying results

jpohhh avatar Oct 26 '14 14:10 jpohhh

Thanks! I had exactly the same problem as jpohh and changing the code in TPKeyboardAvoiding_keyboardWillShow as fabianz66 described fixed it. However I'm using xib's with autolayout instead of storyboard.

leszek-s avatar Nov 27 '14 11:11 leszek-s

I still have this problem. Is there another approach to fix it?

zerox1212 avatar Jan 02 '17 21:01 zerox1212