I have designed a sign up form like following , which contains several textfields and every time user clicks on a textfield the keyboard comes up or the datePicker for birthday date. the sign up form comes up using tap.
But the form itself jumps up and cover the whole screen,
How can I change the viewDidLoad and also the design of my code to 1)have the sign up form in a scroll view format so that I avoid the form jump up in the screen?
- (UIView *)signUpForm
{
if (!_signUpForm) {
CGRect frame = CGRectMake(0.0, kSignUpViewVisibleHeight, kDeviceWidth, 310.0);
UIView *container = [[UIView alloc] initWithFrame:frame];
CGFloat y = 15.0;
frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, kDefaultTextFieldHeight);
UITextField *field = [[UITextField alloc] initWithFrame:frame];
field.placeholder = @"Email*";
field.keyboardType = UIKeyboardTypeEmailAddress;
[container addSubview:field];
self.Email = field;
self. Email.delegate = self;
self.Email.clearButtonMode = UITextFieldViewModeWhileEditing;
CGFloat spacing = 8.0;
y = frame.origin.y + kDefaultTextFieldHeight + spacing;
frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, kDefaultTextFieldHeight);
field = [[UITextField alloc] initWithFrame:frame];
field.placeholder = @"Password*";
field.secureTextEntry = YES;
[container addSubview:field];
self.password = field;
self.password.delegate = self;
self. password.autocapitalizationType = UITextAutocapitalizationTypeNone;
self. password.clearButtonMode = UITextFieldViewModeWhileEditing;
frame.size.height = 200.0;
y = frame.origin.y + kDefaultTextFieldHeight + spacing;
frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, kDefaultTextFieldHeight);
field = [[UITextField alloc] initWithFrame:frame];
field.placeholder = @"Confirm Password*";
field.secureTextEntry = YES;
[container addSubview:field];
self.ConfirmPassword = field;
self. ConfirmPassword.delegate = self;
self. ConfirmPassword.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.registrationFormConfirmPassword.clearButtonMode = UITextFieldViewModeWhileEditing;
y = frame.origin.y + kDefaultTextFieldHeight + 16.0;
CGFloat w = (kDeviceWidth - 2 * 15.0) / 2;
frame = CGRectMake(15.0, y, w - 2.0, kDefaultTextFieldHeight);
field = [[UITextField alloc] initWithFrame:frame];
field.placeholder = @"First Name*";
[container addSubview:field];
self.firstName = field;
self. firstName.delegate = self;
self. firstName.clearButtonMode = UITextFieldViewModeWhileEditing;
frame = CGRectMake(15.0 + w + 2.0, y, w - 2.0, kDefaultTextFieldHeight);
field = [[UITextField alloc] initWithFrame:frame];
field.placeholder = @"Last Name*";
[container addSubview:field];
self.lastName = field;
self.lastName.delegate = self;
self.lastName.clearButtonMode = UITextFieldViewModeWhileEditing;
y = frame.origin.y + kDefaultTextFieldHeight + spacing;
frame = CGRectMake(15.0, y, w, kDefaultTextFieldHeight);
field = [[UITextField alloc] initWithFrame:frame];
[self.appDel.styleManager decorateTextField:field];
field.placeholder = @"Birthday";
[container addSubview:field];
self.Birthday = field;
self.Birthday.delegate = self;
UIButton *signUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
signUpButton.frame = frame;
[signUpButton setTitle:@"Sign Up" forState:UIControlStateNormal];
[signUpButton addTarget:self action:@selector(signUp:) forControlEvents:UIControlEventTouchUpInside]; [container addSubview:signUpButton];
y = frame.origin.y + kDefaultTextFieldHeight + 8.0;
frame = CGRectMake((container.frame.size.width - 192.0) / 2, y, 192.0, 34.0);
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
cancelButton.frame = frame;
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[self.appDel.styleManager decorateButton:cancelButton];
[cancelButton addTarget:self action:@selector(cancelRegistration:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:cancelButton];
_signUpForm = container;
}
return _ signUpForm;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
self.view.backgroundColor = [self.appDel.styleManager appBackgroundGradientWithFrame:self.view.bounds];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(endPageEdit:)];
tap.delegate = self;
[self.view addGestureRecognizer:tap];
[self.appDel.styleManager decorateButton:self.loginWithEmailButton];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
Here is the solution for this issue, its gona work for sure http://www.iphonesampleapps.com/2009/12/adjust-uitextfield-hidden-behind-keyboard-with-uiscrollview/