当文本框架的框架位于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];
答案 0 :(得分:0)
你需要告诉滚动视图它的内容大小是什么(大概在这种情况下,你希望它与page1 UIView相同):
[self.scrollView setContentSize:page1.bounds.size];
[self.scrollView addSubview:page1];