What I have is 15 text field and because of which I can't set them in one ViewController. I added 15 textfield to the scrollview . But scroll view goes up on removing finger from the screen.
Any idea how to stick to down when scrolled to down?
What I have is 15 text field and because of which I can't set them in one ViewController. I added 15 textfield to the scrollview . But scroll view goes up on removing finger from the screen.
Any idea how to stick to down when scrolled to down?
在你的ViewWillApear
设置你UIScrollview
contentSize
喜欢: -
-(void)viewWillAppear:(BOOL)animated
{
srcScrollView.contentSize = CGSizeMake(320, 500);
[super viewWillAppear:YES];
}
你的 TextFiled 代表看起来像:-
-(void)textFieldDidBeginEditing:(FMTextField *)textField
{
[srcScrollView setContentOffset:CGPointMake(0,textField.center.y-140) animated:YES];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[srcScrollView setContentOffset:CGPointMake(0,0) animated:YES];
return YES;
}
您的 contentSize 似乎不足以显示整个内容。设置contensize如下
//Assuming you have a reference to the 15th textField
CGRect textField15Frame = self.textField15.frame;
CGSize contentSize = self.scrollView.contentSize;
contentSize.height = textField15Frame.origin.y+textField15.size.height+5.0f;
[self.scrollView setContentSize:contentSize];
你必须正确设置contentSize
你的滚动视图。在您的情况下,您只需将内容高度设置为:
lastTextField.frame.origin.y + lastTextField.frame.size.height + 10
其中 10 是您想要的下边距。
下面解决了问题...
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.scrollView setContentSize:CGSizeMake(320, 1200)];
}