textField 仅在 textfield 的框架位于 UIView 顶部时才响应触摸。例如,当我将框架设置为 (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];
最佳答案
您需要告诉 ScrollView 它的内容大小是多少(大概在这种情况下,您希望它与 page1 UIView 相同):
[self.scrollView setContentSize:page1.bounds.size];
[self.scrollView addSubview:page1];
关于UIScrollView中的iOS UITextField没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18279784/