仅当文本框的框架位于UIView的顶部时,textField才响应触摸。例如,当我将框架设置为(0,0,280,100)时,文本字段将响应。但是对于框架(0,100,280,100),它不起作用。
TextField的高度为100。但是它仅在textField的上部响应。
这是代码“无法正常工作”(在iOS 7 beta 5上开发)。感谢帮助!
page1 = [[UIView alloc] initWithFrame: CGRectMake(5, 5, scrollView.frame.size.width-10,self.scrollView.frame.size.height-10)];
userNameInput = [[UITextField alloc]initWithFrame:CGRectMake(6, 6, 280, 100)];
[userNameInput setCenter:CGPointMake(page1.frame.size.width / 2, page1.frame.size.height / 2.5f)];
[userNameInput setTextAlignment:NSTextAlignmentCenter];
[userNameInput setTextColor:[UIColor whiteColor]];
userNameInput.enabled = YES;
userNameInput.userInteractionEnabled = YES;
userNameInput.placeholder = @"Enter...";
userNameInput.autocorrectionType = UITextAutocorrectionTypeNo;
userNameInput.keyboardType = UIKeyboardTypeDefault;
userNameInput.returnKeyType = UIReturnKeyDone;
userNameInput.clearButtonMode = UITextFieldViewModeWhileEditing;
userNameInput.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
userNameInput.font = [SystemUtils getSystemFontWithTextSize:30.0f];
userNameInput.delegate = self;
userNameInput.tag = 1;
page1.userInteractionEnabled = YES;
[page1 addSubview:userNameInput];
[userNameInput setBackgroundColor:[UIColor blueColor]];
[page1 setBackgroundColor:[UIColor redColor]];
[scrollView setBackgroundColor:[UIColor greenColor]];
[self.scrollView addSubview:page1];
最佳答案
您需要告诉滚动视图其内容大小是多少(大概在这种情况下,您希望它与page1 UIView相同):
[self.scrollView setContentSize:page1.bounds.size];
[self.scrollView addSubview:page1];