Created
January 25, 2013 19:08
-
-
Save pietrorea/4636954 to your computer and use it in GitHub Desktop.
How to move a UIView above the keyboard when the keyboard comes on screen. The method keyboardWillShow handles the notification UIKeyboardWillShowNotification.
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
- (void)keyboardWillShow:(NSNotification *)notification { | |
CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; | |
CGRect convertedFrame = [self.view convertRect:keyboardFrame fromView:self.view.window]; | |
CGFloat animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | |
UIViewAnimationCurve animationCurve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue]; | |
[UIView animateWithDuration:animationDuration delay:0 options:animationCurve animations:^{ | |
self.viewToMove.bottom = self.view.height - convertedFrame.size.height - 15; | |
} completion:nil]; | |
} |
Oh, that's left over from the app I wrote it for. Good catch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Pietro, this is useful, thanks. Question: what's the -15 magic number for?