0

我设计了一个像下面这样的注册表单,其中包含几个文本字段,每次用户点击一个文本字段时,键盘都会出现或 datePicker 用于生日日期。使用点击出现注册表单。

但是表格本身会跳起来覆盖整个屏幕,

如何将 viewDidLoad 以及我的代码设计更改为 1) 将注册表单设置为滚动视图格式,以避免表单在屏幕上跳起?

- (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];
4

1 回答 1

0

这是这个问题的解决方案,它肯定会工作 http://www.iphonesampleapps.com/2009/12/adjust-uitextfield-hidden-behind-keyboard-with-uiscrollview/

于 2013-02-20T12:47:55.480 回答