diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index 614ab6c6..fe199fcd 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -43,7 +43,7 @@ - (TPKeyboardAvoidingState*)keyboardAvoidingState { - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification { CGRect keyboardRect = [self convertRect:[[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil]; - if (CGRectIsEmpty(keyboardRect)) { + if (CGRectIsEmpty(keyboardRect) || !CGRectIntersectsRect(keyboardRect, self.bounds)) { return; } @@ -79,22 +79,27 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification { self.contentSize = [self TPKeyboardAvoiding_calculatedContentSizeFromSubviewFrames]; } } - + int curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]; + float duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; + if (curve == 0) + curve = 7; + if (duration == 0) + duration = 0.25; // Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited [UIView beginAnimations:nil context:NULL]; - [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]]; - [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]]; + [UIView setAnimationCurve:curve]; + [UIView setAnimationDuration:duration]; self.contentInset = [self TPKeyboardAvoiding_contentInsetForKeyboard]; + self.scrollIndicatorInsets = self.contentInset; + [self layoutIfNeeded]; 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; - [self layoutIfNeeded]; [UIView commitAnimations]; } diff --git a/TPKeyboardAvoidingSample/TPKAScrollViewController.m b/TPKeyboardAvoidingSample/TPKAScrollViewController.m index 4c3fb845..a7a18fc8 100644 --- a/TPKeyboardAvoidingSample/TPKAScrollViewController.m +++ b/TPKeyboardAvoidingSample/TPKAScrollViewController.m @@ -27,6 +27,8 @@ - (void)viewDidLoad { textField.translatesAutoresizingMaskIntoConstraints = NO; textField.placeholder = [NSString stringWithFormat:@"Field %d", i]; textField.borderStyle = UITextBorderStyleRoundedRect; + textField.secureTextEntry = i == 39; + [self.scrollView addSubview:textField]; [self.scrollView addConstraint:[NSLayoutConstraint constraintWithItem:textField attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:30]];