views:

137

answers:

1

Hello, I have an UIScrollView and in the lower part of the screen is a textfield. When I select the textfield the keyboard is displayed above the textfield. The UIView within the UIScrollView is not large enough to scroll up and free some space for the keyboard. So I've tried to enlarge the UIView programaticly. This is what I've got:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {


UIScrollView *scrollView = (UIScrollView *)[[self view] viewWithTag: 2];
UIView *contentview = [[self view] viewWithTag: 3];

CGRect rect = contentview.frame;

rect.size.height = 650;
contentview.frame = rect;

[scrollView setContentSize: contentview.frame.size];

//first try
rect.origin.y = 450;
[scrollView scrollRectToVisible: rect animated: YES]; 

//second try
CGPoint point = CGPointMake(0, 450);
[scrollView setContentOffset: point animated: YES];

return YES;
}

thanks.

A: 

You can register to receive the UIKeyboardWillShowNotification in your view controller. Then move the view controller's view frame up by the size of the keyboard which is provided in the notification.

CGRect frame = self.view.frame;
frame.origin.y -= keyboard.size.height;
self.view.frame = frame;

Do the opposite for UIKeyboardWillHideNotification.

progrmr