Created
April 18, 2012 21:57
-
-
Save casspangell/2416886 to your computer and use it in GitHub Desktop.
Some Xcode Keyboard Delegates
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
#pragma mark - keyboard delegates | |
-(void) textFieldDidBeginEditing:(UITextField *)textFieldView | |
{ | |
currentTextField = textFieldView; | |
} | |
- (BOOL)textFieldShouldReturn:(UITextField *)textField | |
{ | |
if(textField == titleOfImageTextField) | |
{ | |
[urlOfImageTextFiled becomeFirstResponder]; | |
sendButton.hidden = NO; | |
} | |
else | |
{ | |
assert(textField == urlOfImageTextFiled); | |
[textField resignFirstResponder]; | |
if([titleOfImageTextField.text compare:@""] != NSOrderedSame) | |
{ | |
sendButton.hidden = NO; | |
} | |
} | |
return YES; | |
} | |
-(void) textFieldDidEndEditing:(UITextField *) textFieldView | |
{ | |
currentTextField = nil; | |
} | |
-(void) keyboardDidShow:(NSNotification *) notification | |
{ | |
if (keyboardIsShown) { | |
return; | |
} | |
NSDictionary* info = [notification userInfo]; | |
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; | |
CGSize keyboardSize = [aValue CGRectValue].size; | |
//Create offset for the view to move above the keyboard | |
offset = theScroll.contentOffset; | |
CGRect viewFrame = theScroll.frame; | |
viewFrame.size.height -= keyboardSize.height; | |
theScroll.frame = viewFrame; | |
CGRect textFieldRect = [currentTextField frame]; | |
textFieldRect.origin.y += 100; //this number you might want to adjust | |
[theScroll scrollRectToVisible: textFieldRect animated:YES]; | |
keyboardIsShown = YES; | |
} | |
-(void) keyboardDidHide:(NSNotification *) notification | |
{ | |
if (!keyboardIsShown) { | |
return; | |
} | |
theScroll.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH, SCROLLVIEW_CONTENT_HEIGHT); | |
theScroll.contentOffset = offset; | |
keyboardIsShown = NO; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment