Permalink
Browse files

Prevent the loose of the real initial Inset.

When the user pass from on textfield to another one directly, no keyboard events are called.
But if those two textfields haven't the same input views so only a KeyBoardWillShow event is thrown (it isn't balanced with a KeyBoardWillHide) and then the _priorInset will saved the current inset which is the modified one (not the original one).
  • Loading branch information...
1 parent 33d145f commit b1c43482628526d7ec0dc3f4aba23e9f65986482 @jfradj jfradj 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 b1c4348

Please sign in to comment.