-
-
Save seanwolter/5622650 to your computer and use it in GitHub Desktop.
This file contains hidden or 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)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