我在视图中添加了一个滚动视图,如下所示:
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
_scrollView.contentSize = CGSizeMake(320, 600);
[_scrollView setUserInteractionEnabled:TRUE];
[_scrollView setScrollEnabled:TRUE];
[container addSubview:self.scrollView];
但是滚动条显示在屏幕上,我可以滚动它,但里面的 texfields 不起作用。我该如何解决这个问题?
- (UIView *)Form
{
if (!_Form) {
CGRect frame = CGRectMake(0.0, kSignUpViewVisibleHeight, kDeviceWidth, 310.0);
UIView *container = [[UIView alloc] initWithFrame:frame];
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
_scrollView.contentSize = CGSizeMake(320, 600);
[_scrollView setUserInteractionEnabled:TRUE];
[_scrollView setScrollEnabled:TRUE];
CGFloat y = 15.0;
frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, kDefaultTextFieldHeight);
UITextField *field = [[UITextField alloc] initWithFrame:frame];
[self.appDel.styleManager decorateTextField:field];
field.placeholder = @"Email*";
field.keyboardType = UIKeyboardTypeEmailAddress;
[container addSubview:field];
self.FormEmail = field;
self.FormEmail.delegate = self;
self.FormEmail.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.FormEmail.clearButtonMode = UITextFieldViewModeAlways;
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];
[self.appDel.styleManager decorateTextField:field];
field.placeholder = @"Password*";
field.secureTextEntry = YES;
[container addSubview:field];
self.FormPassword = field;
self.FormPassword.delegate = self;
self.FormPassword.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.FormPassword.clearButtonMode = UITextFieldViewModeAlways;
y = frame.origin.y + kDefaultTextFieldHeight + spacing;
frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, kDefaultTextFieldHeight);
field = [[UITextField alloc] initWithFrame:frame];
[self.appDel.styleManager decorateTextField:field];
field.placeholder = @"Confirm Password*";
field.secureTextEntry = YES;
[container addSubview:field];
self.FormConfirmPassword = field;
self.FormConfirmPassword.delegate = self;
self.FormConfirmPassword.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.FormConfirmPassword.clearButtonMode = UITextFieldViewModeAlways;
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];
[self.appDel.styleManager decorateTextField:field];
field.placeholder = @"First Name*";
[container addSubview:field];
self.FirstName = field;
self.FirstName.delegate = self;
self.FirstName.clearButtonMode =UITextFieldViewModeAlways;
frame = CGRectMake(15.0 + w + 2.0, y, w - 2.0, kDefaultTextFieldHeight);
field = [[UITextField alloc] initWithFrame:frame];
[self.appDel.styleManager decorateTextField:field];
field.placeholder = @"Last Name*";
[container addSubview:field];
self.FormLastName = field;
self.FormLastName.delegate = self;
self.FormLastName.clearButtonMode =UITextFieldViewModeAlways;
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.FormBirthday = field;
self.FormBirthday.delegate = self;
frame = CGRectMake(15.0 + w + 5.0, y, w - 5.0, kDefaultTextFieldHeight);
SegmentControl *gender = [[SegmentControl alloc] initWithFrame:frame items:@[@"Boy", @"Girl"]];
[container addSubview:gender];
self.Formtype = gender;
y = frame.origin.y + kDefaultTextFieldHeight + 20.0;
frame = CGRectMake((container.frame.size.width - 192.0) / 2, y, 192.0, 33.0);
UIButton *signUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
signUpButton.frame = frame;
[signUpButton setTitle:@"Sign Up" forState:UIControlStateNormal];
[self.appDel.styleManager decorateButton:signUpButton];
[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];
[container addSubview:self.scrollView];
_Form = container;
}
return _Form;
}
我添加了需要滚动的表单。