With the iOS SDK: 使用iOS SDK: ide
I have a UIView
with UITextField
s that bring up a keyboard. 我有一個帶有UITextField
的UIView
, UITextField
一個鍵盤。 I need it to be able to: 我須要它可以: ui
Allow scrolling of the contents of the UIScrollView
to see the other text fields once the keyboard is brought up 提起鍵盤後,容許滾動UIScrollView
的內容以查看其餘文本字段 this
Automatically "jump" (by scrolling up) or shortening 自動「跳躍」(經過向上滾動)或縮短 spa
I know that I need a UIScrollView
. 我知道我須要一個UIScrollView
。 I've tried changing the class of my UIView
to a UIScrollView
but I'm still unable to scroll the textboxes up or down. 我嘗試將UIView
的類更改成UIScrollView
但仍然沒法向上或向下滾動文本框。 .net
Do I need both a UIView
and a UIScrollView
? 我是否須要UIView
和UIScrollView
? Does one go inside the other? 一我的會進入另外一我的嗎? code
What needs to be implemented in order to automatically scroll to the active text field? 爲了自動滾動到活動文本字段,須要實現什麼? component
Ideally as much of the setup of the components as possible will be done in Interface Builder. 理想狀況下,將在Interface Builder中完成儘量多的組件設置。 I'd like to only write code for what needs it. 我只想編寫所需的代碼。 orm
Note: the UIView
(or UIScrollView
) that I'm working with is brought up by a tabbar ( UITabBar
), which needs to function as normal. 注意:我正在使用的UIView
(或UIScrollView
)由一個標籤欄( UITabBar
)調出,該UITabBar
須要正常運行。 get
Edit: I am adding the scroll bar just for when the keyboard comes up. 編輯:我只是在鍵盤出現時添加滾動條。 Even though it's not needed, I feel like it provides a better interface because then the user can scroll and change textboxes, for example. 即便不須要它,我也以爲它提供了一個更好的界面,由於例如,用戶能夠滾動和更改文本框。 it
I've got it working where I change the frame size of the UIScrollView
when the keyboard goes up and down. 我能夠在鍵盤上下移動時更改UIScrollView
的幀大小的地方工做。 I'm simply using: 我只是在使用:
-(void)textFieldDidBeginEditing:(UITextField *)textField { //Keyboard becomes visible scrollView.frame = CGRectMake(scrollView.frame.origin.x, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height - 215 + 50); //resize } -(void)textFieldDidEndEditing:(UITextField *)textField { //keyboard will hide scrollView.frame = CGRectMake(scrollView.frame.origin.x, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height + 215 - 50); //resize }
However, this doesn't automatically "move up" or center the lower text fields in the visible area, which is what I would really like. 可是,這不會自動「向上移動」或將下部文本字段居中顯示區域的中心,這是我真正想要的。