滚动后,UITcrollView中的UITextFied未启用

我在ViewController中添加了UIScrollView ,并在该UIScrollView下添加了UIView

我在该UIView添加了10个UITextFields ,滚动工作正常

在Simulator / iPhone中运行应用程序时,前6个UITextFields在屏幕上显示而不滚动,剩余的4个UITextFields不工作[对触摸没有响应],这将在滚动后显示

请任何人指导我解决这个问题?

谢谢

更新:我在ViewController中使用它

 override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: 1070); } 

ViewControllerStructure如下 在这里输入图像说明

试试这个代码对我有用

在.h

 { IBOutlet UIScrollView *scrView; UITextField *currentTextField; BOOL keyboardIsShown; } -(IBAction)backButtonClicked:(id)sender; 

和.m文件中

 //---size of keyboard--- CGRect keyboardBounds; //---size of application screen--- CGRect applicationFrame; //---original size of ScrollView--- CGSize scrollViewOriginalSize; - (void)moveScrollView:(UIView *) theView { //---get the y-coord of the view--- CGFloat viewCenterY = theView.center.y; //---calculate how much free space is left--- CGFloat freeSpaceHeight = applicationFrame.size.height - keyboardBounds.size.height; CGFloat scrollAmount = viewCenterY - freeSpaceHeight / 2.5; if (scrollAmount < 0) scrollAmount = 0; //---set the new scrollView contentSize--- scrView.contentSize = CGSizeMake( applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height); //---scroll the ScrollView--- [scrView setContentOffset:CGPointMake(0, scrollAmount) animated:YES]; } //---when a TextField view begins editing--- - (void)textFieldDidBeginEditing:(UITextField *)textFieldView { [self moveScrollView:textFieldView]; } //---when a TextField view is done editing--- - (void)textFieldDidEndEditing:(UITextField *) textFieldView { //[scrollView setContentOffset:CGPointMake(0, -(dis * 2.0)) animated:YES]; [UIView beginAnimations:@"back to original size" context:nil]; scrView.contentSize = scrollViewOriginalSize; [UIView commitAnimations]; } //---when the keyboard appears--- - (void)keyboardWillShow:(NSNotification *) notification { //---gets the size of the keyboard--- NSDictionary *userInfo = [notification userInfo]; NSValue *keyboardValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey]; [keyboardValue getValue:&keyboardBounds]; } - (void)keyboardWillHide:(NSNotification *) notification { } -(BOOL)textFieldShouldReturn:(UITextField *)textFieldView { [textFieldView resignFirstResponder]; return NO; } -(void)viewWillAppear:(BOOL)animated { //---registers the notifications for keyboard--- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:self.view.window]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } - (void)viewDidLoad { txt1.keyboardAppearance = UIKeyboardAppearanceAlert; txt2.keyboardAppearance = UIKeyboardAppearanceAlert; txt3.keyboardAppearance = UIKeyboardAppearanceAlert; txt4.keyboardAppearance = UIKeyboardAppearanceAlert; txt5.keyboardAppearance = UIKeyboardAppearanceAlert; txt6.keyboardAppearance = UIKeyboardAppearanceAlert; txt7.keyboardAppearance = UIKeyboardAppearanceAlert; txt8.keyboardAppearance = UIKeyboardAppearanceAlert; txt9.keyboardAppearance = UIKeyboardAppearanceAlert; txt10.keyboardAppearance = UIKeyboardAppearanceAlert; scrollViewOriginalSize = scrView.contentSize; applicationFrame = [[UIScreen mainScreen] applicationFrame]; [super viewDidLoad]; } - (void)dealloc { [scrView release]; [super dealloc]; } 

您的文本字段位于超视界之外。 您应该调整视图的大小,以便所有文本字段都在范围内。