Skip to content

Commit 206c302

Browse files
committed
Bounce fix
1 parent d513f1f commit 206c302

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
@@ -43,7 +43,7 @@ - (TPKeyboardAvoidingState*)keyboardAvoidingState {
4343

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

@@ -79,11 +79,16 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {
7979
self.contentSize = [self TPKeyboardAvoiding_calculatedContentSizeFromSubviewFrames];
8080
}
8181
}
82-
82+
int curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
83+
float duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
84+
if (curve == 0)
85+
curve = 7;
86+
if (duration == 0)
87+
duration = 0.25;
8388
// Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
8489
[UIView beginAnimations:nil context:NULL];
85-
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
86-
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
90+
[UIView setAnimationCurve:curve];
91+
[UIView setAnimationDuration:duration];
8792

8893
self.contentInset = [self TPKeyboardAvoiding_contentInsetForKeyboard];
8994

@@ -93,7 +98,7 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {
9398
[self setContentOffset:CGPointMake(self.contentOffset.x,
9499
[self TPKeyboardAvoiding_idealOffsetForView:firstResponder
95100
withViewingAreaHeight:viewableHeight])
96-
animated:YES];
101+
animated:NO];
97102

98103

99104
[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)