Skip to content

Commit

Permalink
Disable for UICollectionView on iOS 9, which seems to be automatic now
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltyson committed Sep 29, 2015
1 parent b262244 commit a722af6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions TPKeyboardAvoiding/TPKeyboardAvoidingCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ @implementation TPKeyboardAvoidingCollectionView
#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 @@ -45,6 +47,18 @@ -(void)dealloc {
#endif
}


-(BOOL)hasAutomaticKeyboardAvoidingBehaviour {
if ( [[[UIDevice currentDevice] systemVersion] integerValue] >= 9
&& [self.delegate isKindOfClass:[UICollectionViewController class]] ) {
// Theory: It looks like iOS 9's collection views automatically avoid the keyboard. As usual
// Apple have totally failed to document this anywhere, so this is just a guess.
return YES;
}

return NO;
}

-(void)setFrame:(CGRect)frame {
[super setFrame:frame];
[self TPKeyboardAvoiding_updateContentInset];
Expand Down

0 comments on commit a722af6

Please sign in to comment.