Skip to content

Commit eaa88e9

Browse files
committed
Disable UITableView keyboard avoiding on iOS 8.3 SDK and newer
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.
1 parent b154752 commit eaa88e9

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ @implementation TPKeyboardAvoidingTableView
1515
#pragma mark - Setup/Teardown
1616

1717
- (void)setup {
18+
if ( [self hasAutomaticKeyboardAvoidingBehaviour] ) return;
19+
1820
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(TPKeyboardAvoiding_keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil];
1921
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(TPKeyboardAvoiding_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
2022
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollToActiveTextField) name:UITextViewTextDidBeginEditingNotification object:nil];
@@ -44,12 +46,28 @@ -(void)dealloc {
4446
#endif
4547
}
4648

49+
-(BOOL)hasAutomaticKeyboardAvoidingBehaviour {
50+
#if defined(__IPHONE_8_3)
51+
// Apps built using the iOS 8.3 SDK (probably: older SDKs not tested) seem to handle keyboard
52+
// avoiding automatically. This doesn't seem to be documented anywhere by Apple. Note: this only
53+
// applies to UITableView.
54+
return YES;
55+
#endif
56+
57+
return NO;
58+
}
59+
4760
-(void)setFrame:(CGRect)frame {
4861
[super setFrame:frame];
62+
if ( [self hasAutomaticKeyboardAvoidingBehaviour] ) return;
4963
[self TPKeyboardAvoiding_updateContentInset];
5064
}
5165

5266
-(void)setContentSize:(CGSize)contentSize {
67+
if ( [self hasAutomaticKeyboardAvoidingBehaviour] ) {
68+
[super setContentSize:contentSize];
69+
return;
70+
}
5371
if (CGSizeEqualToSize(contentSize, self.contentSize)) {
5472
// Prevent triggering contentSize when it's already the same
5573
// this cause table view to scroll to top on contentInset changes

0 commit comments

Comments
 (0)