Created
April 25, 2013 10:04
-
-
Save siqin/5458759 to your computer and use it in GitHub Desktop.
Perfectly following keyboard height change.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - reg & unreg notification | |
- (void)regNotification | |
{ | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; | |
} | |
- (void)unregNotification | |
{ | |
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil]; | |
} | |
#pragma mark - notification handler | |
- (void)keyboardWillChangeFrame:(NSNotification *)notification | |
{ | |
NSDictionary *info = [notification userInfo]; | |
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; | |
CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; | |
CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y; | |
CGRect inputFieldRect = self.inputTextField.frame; | |
CGRect moreBtnRect = self.moreInputTypeBtn.frame; | |
inputFieldRect.origin.y += yOffset; | |
moreBtnRect.origin.y += yOffset; | |
[UIView animateWithDuration:duration animations:^{ | |
self.inputTextField.frame = inputFieldRect; | |
self.moreInputTypeBtn.frame = moreBtnRect; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment