开发者

iPhone: Scrolling a UIScrollview While Entering Text into an Embedded UITextView

开发者 https://www.devze.com 2022-12-26 17:15 出处:网络
I have a view composed of a UIScrollView which contains a UITextField, a开发者_如何学Go UILabel and a UITextView. I want to configure the view such that when the user types text into the textview, the

I have a view composed of a UIScrollView which contains a UITextField, a开发者_如何学Go UILabel and a UITextView. I want to configure the view such that when the user types text into the textview, the scrollview will scroll to keep the line being typed visible.


In the -[UITextViewDelegate textView:shouldChangeTextInRange:replacementText:] you will need to monitor the amount of text displayed and calculate whether that has scrolled of the screen. Then adjust the scrollview's setContentOffset:animated: accordingly.

However, the best option is not to try and edit within the scroll view at all. Instead, use a separate detail view to edit the text in and just use the more complicated scroll view to display the text. In other words, think of the scrollview as a table and the textview as a row in the table. You select the textview and it opens a detail view just like it would in a table.

Remember that your users expect hierarchy on an iPhone. Sliding over to another screen to enter text is a very common UI behavior and it won't disorient them. They will appreciate the greater ease of using a view that does nothing but enter the text.

See this question from the sidebar: iPhone Auto-scroll UITextView but allow manual scrolling also

0

精彩评论

暂无评论...
验证码 换一张
取 消