From 61bc975bac003f5a2a34ce66c0e8ec5f89d90c68 Mon Sep 17 00:00:00 2001 From: phatmann Date: Fri, 27 Dec 2013 13:25:13 -0500 Subject: [PATCH] Work without firstResponder --- ...UIScrollView+TPKeyboardAvoidingAdditions.m | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index b1a08246..81dffeb2 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -47,10 +47,6 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification { } UIView *firstResponder = [self TPKeyboardAvoiding_findFirstResponderBeneathView:self]; - if ( !firstResponder ) { - // No child view is the first responder - nothing to do here - return; - } state.keyboardRect = [self convertRect:[[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil]; state.keyboardVisible = YES; @@ -71,13 +67,17 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]]; [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]]; - + self.contentInset = [self TPKeyboardAvoiding_contentInsetForKeyboard]; - CGFloat viewableHeight = self.bounds.size.height - self.contentInset.top - self.contentInset.bottom; - [self setContentOffset:CGPointMake(self.contentOffset.x, - [self TPKeyboardAvoiding_idealOffsetForView:firstResponder - withViewingAreaHeight:viewableHeight]) - animated:NO]; + + if ( firstResponder ) { + CGFloat viewableHeight = self.bounds.size.height - self.contentInset.top - self.contentInset.bottom; + [self setContentOffset:CGPointMake(self.contentOffset.x, + [self TPKeyboardAvoiding_idealOffsetForView:firstResponder + withViewingAreaHeight:viewableHeight]) + animated:NO]; + } + self.scrollIndicatorInsets = self.contentInset; [UIView commitAnimations];