0
As the statement says, As soon as I touch one input
the keyboard goes up and then the view
goes up. I’d like to know what I’m doing wrong.
PS: In addition, between the keyboard and the view, there is a black space and the scroll
view still works, thus making it even uglier with the effect.
#pragma mark - UITextField Delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *guestlistName = [alertView textFieldAtIndex:0].text;
if (buttonIndex == 1) // Cancel
return;
if (guestlistName == nil || [guestlistName length] == 0)
return;
}
// Keyboard handling junk below
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
[self.scrollView scrollRectToVisible:activeField.frame animated:YES];
}
}
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
activeField = textField;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
activeField = nil;
}
- (void) textViewDidBeginEditing:(UITextView *)textView {
activeField = textView;
}
- (void) textViewDidEndEditing:(UITextView *)textView {
activeField = textView;
}
- (void) dismissKeyboard {
[activeField resignFirstResponder];
}
Thanks in Advance!