Skip to content

Commit

Permalink
Add support for keyboard show/hide.
Browse files Browse the repository at this point in the history
  • Loading branch information
duc-ios committed Apr 27, 2015
1 parent ba17c21 commit bf6c89e
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions KLCPopup/KLCPopup.m
Original file line number Diff line number Diff line change
Expand Up @@ -1036,22 +1036,54 @@ - (void)didChangeStatusBarOrientation:(NSNotification*)notification {
#pragma mark - Subclassing

- (void)willStartShowing {

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil];
}


- (void)didFinishShowing {

}


- (void)willStartDismissing {

}


- (void)didFinishDismissing {

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

#pragma mark - Keyboard notification handlers

- (void)keyboardWillShowNotification:(NSNotification *)notification {
[self moveContainerViewForKeyboard:notification up:YES];
}

- (void)keyboardWillHideNotification:(NSNotification *)notification {
[self moveContainerViewForKeyboard:notification up:NO];
}

- (void)moveContainerViewForKeyboard:(NSNotification *)notification up:(BOOL)up {
NSDictionary *userInfo = [notification userInfo];
NSTimeInterval animationDuration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
UIViewAnimationCurve animationCurve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

CGRect frame = _containerView.frame;
if (up) {
frame.origin.y -= keyboardEndFrame.size.height/2;
} else {
frame.origin.y += keyboardEndFrame.size.height/2;
}

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
_containerView.frame = frame;
[UIView commitAnimations];
}

@end
Expand Down

0 comments on commit bf6c89e

Please sign in to comment.