Permalink
Browse files

Merge pull request #8 from jfradj/master

Fix issue related to switching focus between text fields (unbalanced keyboard show/hide notifications)
  • Loading branch information...
2 parents 33d145f + b1c4348 commit 709b08ce6fee9e8f049ec9e23263333b78448435 @michaeltyson committed Feb 2, 2012
@@ -7,6 +7,7 @@
@interface TPKeyboardAvoidingScrollView : UIScrollView {
UIEdgeInsets _priorInset;
+ BOOL _priorInsetSaved;
BOOL _keyboardVisible;
CGRect _keyboardRect;
CGSize _originalContentSize;
@@ -19,6 +19,7 @@ - (CGRect)keyboardRect;
@implementation TPKeyboardAvoidingScrollView
- (void)setup {
+ _priorInsetSaved = NO;
if ( CGSizeEqualToSize(self.contentSize, CGSizeZero) ) {
self.contentSize = self.bounds.size;
}
@@ -81,7 +82,10 @@ - (void)keyboardWillShow:(NSNotification*)notification {
return;
}
- _priorInset = self.contentInset;
+ if (!_priorInsetSaved) {
+ _priorInset = self.contentInset;
+ _priorInsetSaved = YES;
+ }
// Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
[UIView beginAnimations:nil context:NULL];
@@ -105,6 +109,7 @@ - (void)keyboardWillHide:(NSNotification*)notification {
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
self.contentInset = _priorInset;
+ _priorInsetSaved = NO;
[UIView commitAnimations];
}
@@ -7,6 +7,7 @@
@interface TPKeyboardAvoidingTableView : UITableView {
UIEdgeInsets _priorInset;
+ BOOL _priorInsetSaved;
BOOL _keyboardVisible;
CGRect _keyboardRect;
}
@@ -83,7 +83,10 @@ - (void)keyboardWillShow:(NSNotification*)notification {
return;
}
- _priorInset = self.contentInset;
+ if (!_priorInsetSaved) {
+ _priorInset = self.contentInset;
+ _priorInsetSaved = YES;
+ }
// Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
[UIView beginAnimations:nil context:NULL];
@@ -107,6 +110,7 @@ - (void)keyboardWillHide:(NSNotification*)notification {
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
self.contentInset = _priorInset;
+ _priorInsetSaved = NO;
[UIView commitAnimations];
}

0 comments on commit 709b08c

Please sign in to comment.