From eaa88e9dea3f600f35ae88c2f55fb9b06dc005c5 Mon Sep 17 00:00:00 2001 From: Michael Tyson Date: Tue, 23 Jun 2015 13:55:54 +1000 Subject: [PATCH] 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. --- .../TPKeyboardAvoidingTableView.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m b/TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m index 3d50c560..659671c4 100644 --- a/TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m +++ b/TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m @@ -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]; @@ -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