Skip to content

Instantly share code, notes, and snippets.

@MattFoley
Created May 21, 2013 17:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MattFoley/5621517 to your computer and use it in GitHub Desktop.
Save MattFoley/5621517 to your computer and use it in GitHub Desktop.
Number pad Go Button, animation mimicking.
- (void)setupDecimalPadDone
{
self.keyboardShownObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
self.goButton = [UIButton buttonWithType:UIButtonTypeCustom];
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:self.goButton];
CGRect keyboardBeginFrame;
[[note.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardBeginFrame];
self.goButton.frame = CGRectMake(keyboardBeginFrame.origin.x,
(keyboardBeginFrame.origin.y + keyboardBeginFrame.size.height) - 53, 106, 53);
self.goButton.adjustsImageWhenHighlighted = NO;
[self.goButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[self.goButton setImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
[self.goButton addTarget:self action:@selector(fetchLocationResults) forControlEvents:UIControlEventTouchUpInside];
CGPoint newCenter = CGPointMake(self.goButton.superview.frame.origin.x + self.goButton.frame.size.width/2,
self.goButton.superview.frame.size.height - self.goButton.frame.size.height/2);
[UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]
delay:0
options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]
animations:^{self.goButton.center = newCenter;} completion:nil];
}];
self.keyboardHiddenObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
[UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]
delay:0
options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]
animations:^{
CGRect keyboardEndFrame;
[[note.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
self.goButton.frame = CGRectMake(keyboardEndFrame.origin.x + 106/2,
(keyboardEndFrame.origin.y + keyboardEndFrame.size.height) - 53/2, 106, 53);
} completion:^(BOOL finished) {
if (finished){
[self.goButton removeTarget:self
action:@selector(fetchLocationResults)
forControlEvents:UIControlEventTouchUpInside];
[self.goButton removeFromSuperview];
}}];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment