From 86f15a65514b8379bb98a1c6b957350c72f8dc95 Mon Sep 17 00:00:00 2001 From: Igor Arsenkin Date: Thu, 23 Mar 2017 16:11:17 +0200 Subject: [PATCH 1/2] Update UIScrollView+TPKeyboardAvoidingAdditions.m Stable work on iOS 10. I observed periodic problems when the text field was shifted upwards. Sometimes the text field shifts up, and sometimes it does not. This commit fixes this bug. --- .../UIScrollView+TPKeyboardAvoidingAdditions.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index 834b6e80..ac3e08da 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -12,6 +12,7 @@ static const CGFloat kCalculatedContentPadding = 10; static const CGFloat kMinimumScrollOffsetPadding = 20; +static const CGFloat kAnimationDuration = 0.25; static const int kStateKey; @@ -217,11 +218,10 @@ -(void)TPKeyboardAvoiding_scrollToActiveTextField { // Ordinarily we'd use -setContentOffset:animated:YES here, but it interferes with UIScrollView // behavior which automatically ensures that the first responder is within its bounds - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self setContentOffset:idealOffset animated:YES]; - + [UIView animateWithDuration:kAnimationDuration animations:^{ + self.contentOffset = idealOffset; state.ignoringNotifications = NO; - }); + }]; } #pragma mark - Helpers From 68b0e4db2b9756bf59ea990f7897d4e1fbb5d400 Mon Sep 17 00:00:00 2001 From: Igor Arsenkin Date: Fri, 24 Mar 2017 12:09:50 +0200 Subject: [PATCH 2/2] Update UIScrollView+TPKeyboardAvoidingAdditions.m Stable work on iOS 10, iOS 9. I observed periodic problems when the text field was shifted upwards. Sometimes the text field shifts up, and sometimes it does not. This commit fixes this bug. --- .../UIScrollView+TPKeyboardAvoidingAdditions.m | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index ac3e08da..172f0079 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -12,7 +12,8 @@ static const CGFloat kCalculatedContentPadding = 10; static const CGFloat kMinimumScrollOffsetPadding = 20; -static const CGFloat kAnimationDuration = 0.25; + +static NSString * const kUIKeyboardAnimationDurationUserInfoKey = @"UIKeyboardAnimationDurationUserInfoKey"; static const int kStateKey; @@ -27,6 +28,7 @@ @interface TPKeyboardAvoidingState : NSObject @property (nonatomic, assign) BOOL priorPagingEnabled; @property (nonatomic, assign) BOOL ignoringNotifications; @property (nonatomic, assign) BOOL keyboardAnimationInProgress; +@property (nonatomic, assign) CGFloat animationDuration; @end @implementation UIScrollView (TPKeyboardAvoidingAdditions) @@ -44,14 +46,16 @@ - (TPKeyboardAvoidingState*)keyboardAvoidingState { } - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification { + NSDictionary *info = [notification userInfo]; + TPKeyboardAvoidingState *state = self.keyboardAvoidingState; + + state.animationDuration = [[info objectForKey:kUIKeyboardAnimationDurationUserInfoKey] doubleValue]; - CGRect keyboardRect = [self convertRect:[[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil]; + CGRect keyboardRect = [self convertRect:[[info objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil]; if (CGRectIsEmpty(keyboardRect)) { return; } - - TPKeyboardAvoidingState *state = self.keyboardAvoidingState; - + if ( state.ignoringNotifications ) { return; } @@ -218,8 +222,9 @@ -(void)TPKeyboardAvoiding_scrollToActiveTextField { // Ordinarily we'd use -setContentOffset:animated:YES here, but it interferes with UIScrollView // behavior which automatically ensures that the first responder is within its bounds - [UIView animateWithDuration:kAnimationDuration animations:^{ + [UIView animateWithDuration:state.animationDuration animations:^{ self.contentOffset = idealOffset; + } completion:^(BOOL finished) { state.ignoringNotifications = NO; }]; }