开发者

How to position my UIScrollView and Text Field inside?

You may find my question stupid but I'm new to Objective C dev and I'm still learning basic things. I made a 开发者_高级运维form in my app with a text field in the bottom of the view. But when this field get the focus, keyboard shows up and it hides the field so no way to see what I'm typing. I've found solutions online about it especially with the use of UIScrollView to fix the issue.

The issue I've now is with the Scroll View itself. I moved my text field to replace it with a UIScrollView of about same size, then I drag drop my field back but this time as a subview of the ScrollView. But when running the app the text field is going up, that is its position in interface builder is different to what I can see when running the app.

I need your help about the size I need to apply to the Scroll View and its content to make it useful in this case. Should it have the exact size as the text field ? should it have the same size as the whole view ?

Thx for helping,

Stephane


A UIScrollView has two "sizes". The one is that of its own frame (i.e. how much space does it take up). And how large is the contentSize of the scrollview (i.e. how far left/right/up/down can we scroll)

The general Idea would be this:

  • your UIScrollView has the size of the available screen real estate when the keyboard is hidden (say 320 x 460 or so), it takes up as much space as its content (assuming your content also needs 320 x 460), scrolling isn't enabled.

  • once the keyboard shows, the scrollView will have to scale down (say 320 x 244), the content obviously doesn't scale down, that way you're now able to scroll.

I'd probably use something like

moveTextViewForKeyboard:(NSNotification*)aNotification up: (BOOL) up

to trigger the frameSize change of the scrollView and enable scrolling.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜