Skip to content

Commit

Permalink
Disable UITableView keyboard avoiding on iOS 8.3 SDK and newer
Browse files Browse the repository at this point in the history
Apps built using the iOS 8.3 SDK (probably: older SDKs not tested) seem to handle keyboard avoiding automatically. This doesn't seem to be documented anywhere by Apple. Note: this only applies to UITableView.
  • Loading branch information
michaeltyson committed Jun 23, 2015
1 parent b154752 commit eaa88e9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ @implementation TPKeyboardAvoidingTableView
#pragma mark - Setup/Teardown

- (void)setup {
if ( [self hasAutomaticKeyboardAvoidingBehaviour] ) return;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(TPKeyboardAvoiding_keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(TPKeyboardAvoiding_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollToActiveTextField) name:UITextViewTextDidBeginEditingNotification object:nil];
Expand Down Expand Up @@ -44,12 +46,28 @@ -(void)dealloc {
#endif
}

-(BOOL)hasAutomaticKeyboardAvoidingBehaviour {
#if defined(__IPHONE_8_3)
// Apps built using the iOS 8.3 SDK (probably: older SDKs not tested) seem to handle keyboard
// avoiding automatically. This doesn't seem to be documented anywhere by Apple. Note: this only
// applies to UITableView.
return YES;
#endif

return NO;
}

-(void)setFrame:(CGRect)frame {
[super setFrame:frame];
if ( [self hasAutomaticKeyboardAvoidingBehaviour] ) return;
[self TPKeyboardAvoiding_updateContentInset];
}

-(void)setContentSize:(CGSize)contentSize {
if ( [self hasAutomaticKeyboardAvoidingBehaviour] ) {
[super setContentSize:contentSize];
return;
}
if (CGSizeEqualToSize(contentSize, self.contentSize)) {
// Prevent triggering contentSize when it's already the same
// this cause table view to scroll to top on contentInset changes
Expand Down

3 comments on commit eaa88e9

@gordontucker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this made the keyboard avoiding tableview quit working at all our apps in 8.3. Not sure why 8.3 would have fixed keyboard avoiding for you, but it did not fix it for our apps. Figured you may care to know. If not then feel free to ignore my comment :)

@chillpop
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second @gordontucker. This change has caused keyboard avoiding to break for me too.

@michaeltyson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, you're right; alas, none of this is documented so we're flying blind. Looks like this behaviour only affects UITableViewController, so for straight UIViewControllers, TPKeyboardAvoiding's still needed. Try SHA d891e1e.

Please sign in to comment.