Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit b1c43482628526d7ec0dc3f4aba23e9f65986482 1 parent 33d145f
@jfradj jfradj authored
View
1  TPKeyboardAvoidingScrollView.h
@@ -7,6 +7,7 @@
@interface TPKeyboardAvoidingScrollView : UIScrollView {
UIEdgeInsets _priorInset;
+ BOOL _priorInsetSaved;
BOOL _keyboardVisible;
CGRect _keyboardRect;
CGSize _originalContentSize;
View
7 TPKeyboardAvoidingScrollView.m
@@ -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];
}
View
1  TPKeyboardAvoidingTableView.h
@@ -7,6 +7,7 @@
@interface TPKeyboardAvoidingTableView : UITableView {
UIEdgeInsets _priorInset;
+ BOOL _priorInsetSaved;
BOOL _keyboardVisible;
CGRect _keyboardRect;
}
View
6 TPKeyboardAvoidingTableView.m
@@ -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];
}
Please sign in to comment.
Something went wrong with that request. Please try again.