views:

53

answers:

1

I have a UIView with another UIView inside it. On the inside UIView there is a textbox which I want to fill in. When I try to fill it in the keyboard blocks my view:

The UIViewController has the following

containerView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view=containerView;
//The apropriate releases etc are further on...

When I touch it, the keyboard comes up as expected, but blocks the textbox I'm trying to fill in. How can I force the view to slide up?

The front view

OptionsFront * fv = [[OptionsFront alloc] initWithFrame:[UIScreen mainScreen].bounds];
[containerView addSubview:frontView];

In the front view is a subview

CGRect bounds = CGRectMake(0.0f, 210.0f, 280.0f, 130.0f);
sv = [[UIView alloc] initWithFrame:bounds];
[self addSubview:sv]; //added to frontView

In sv is a textbox near the botton:

rect = CGRectMake(70.0f, 20.0f, 100.0f, 27.0f);
cf = [self createTextField_Rounded:rect holder:@"+ve"];
[sv addSubview:cf];

So cf happens to be near the bottom of the page. I expected that when I select it, the whole display would move up, but the keyboard just moves up and blocks it.

What can I do?

Appendix:

- (UITextField *)createTextField_Rounded:(CGRect) frame holder:(NSString *) ph
{
UITextField *returnTextField = [[UITextField alloc] initWithFrame:frame];
returnTextField.borderStyle = UITextBorderStyleRoundedRect;
    returnTextField.textColor = [UIColor blackColor];
returnTextField.font = [UIFont systemFontOfSize:17.0];
returnTextField.delegate = self;
returnTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
returnTextField.returnKeyType = UIReturnKeyDone;

returnTextField.clearButtonMode = UITextFieldViewModeWhileEditing;

return returnTextField;
}
+3  A: 

you need to move the textField up. in your UITextField delegate implement something like (from memory):

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    textField.superview.frame = CGRectMake(0.0f, 100.0f, 280.0f, 130.0f); // experiment with frame size
    [UIView commitAnimations];
}

and you'll want to move it back in textFieldDidEndEditing:

Meltemi
Thanks! Very elegant solution!
John Smith