我所擁有的是15個文本框,並且因此我無法在一個ViewController中設置它們。我向滾動視圖添加了15個文本框。但滾動視圖會將手指從屏幕上移開。如何在一個視圖控制器中使用滾動視圖設置15個文本框
任何想法如何滾動下來時堅持下來?
我所擁有的是15個文本框,並且因此我無法在一個ViewController中設置它們。我向滾動視圖添加了15個文本框。但滾動視圖會將手指從屏幕上移開。如何在一個視圖控制器中使用滾動視圖設置15個文本框
任何想法如何滾動下來時堅持下來?
在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;
}
我正在使用Storyboard – 2013-03-05 07:51:16
檢查我的更新回答我的朋友:) – 2013-03-05 07:55:37
現在我有另一個問題。我有導航欄。我有滾動視圖在x = 0,y = 150,但它仍然顯示在0,0在iphone – 2013-03-05 09:05:55
你必須正確設置滾動視圖的contentSize
。在你的情況下,你只需要將內容高度設置爲:
lastTextField.frame.origin.y + lastTextField.frame.size.height + 10
其中10是您想要的底部邊距。
以下解決好像你的contentSize是不是大到足以顯示全部內容的問題......
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.scrollView setContentSize:CGSizeMake(320, 1200)];
}
。設置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];
給一些其他的代碼其難度 – Durgaprasad 2013-03-05 07:45:47
我的第一個猜測是,你沒有正確設置你的滾動視圖的contentSize – 2013-03-05 07:48:49
可以使文本框這樣http://rajneesh071.blogspot.in/ 2012/09/make-label-and-button.html – Rajneesh071 2013-03-05 08:02:47