Skip to content

Commit d56b5de

Browse files
committed
Bounce fix
1 parent d418b6f commit d56b5de

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ - (TPKeyboardAvoidingState*)keyboardAvoidingState {
4444

4545
- (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {
4646
CGRect keyboardRect = [self convertRect:[[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil];
47-
if (CGRectIsEmpty(keyboardRect)) {
47+
if (CGRectIsEmpty(keyboardRect) || !CGRectIntersectsRect(keyboardRect, self.bounds)) {
4848
return;
4949
}
5050

@@ -76,11 +76,16 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {
7676
self.contentSize = [self TPKeyboardAvoiding_calculatedContentSizeFromSubviewFrames];
7777
}
7878
}
79-
79+
int curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
80+
float duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
81+
if (curve == 0)
82+
curve = 7;
83+
if (duration == 0)
84+
duration = 0.25;
8085
// Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
8186
[UIView beginAnimations:nil context:NULL];
82-
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
83-
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
87+
[UIView setAnimationCurve:curve];
88+
[UIView setAnimationDuration:duration];
8489

8590
self.contentInset = [self TPKeyboardAvoiding_contentInsetForKeyboard];
8691

@@ -90,7 +95,7 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {
9095
[self setContentOffset:CGPointMake(self.contentOffset.x,
9196
[self TPKeyboardAvoiding_idealOffsetForView:firstResponder
9297
withViewingAreaHeight:viewableHeight])
93-
animated:YES];
98+
animated:NO];
9499

95100

96101
[UIView commitAnimations];

TPKeyboardAvoidingSample/TPKAScrollViewController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ - (void)viewDidLoad {
2727
textField.translatesAutoresizingMaskIntoConstraints = NO;
2828
textField.placeholder = [NSString stringWithFormat:@"Field %d", i];
2929
textField.borderStyle = UITextBorderStyleRoundedRect;
30+
textField.secureTextEntry = i == 39;
31+
3032
[self.scrollView addSubview:textField];
3133

3234
[self.scrollView addConstraint:[NSLayoutConstraint constraintWithItem:textField attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:30]];

0 commit comments

Comments
 (0)