views:

148

answers:

2

I have a modal view with a textview and a button. When the keyboard is displayed it covers up some of my UI elements. I'd like my modal to be scrollable so that it can be viewed while the keyboard is displayed. How can I do this?

A: 

Use a UIScrollView instead of an ordinary UIView. You can disable scrolling when you don't want the user to be able to with:

[theView setScrollEnabled:NO];
Tom Irving
Can I place a UIScrollView inside of a UIView and have it contain my other UIControls?
Sheehan Alam
Yes you can. Or you can replace the UIView with the UIScrollView as the UIScrollView is a subclass of UIView and thus does everything like a UIView and more (the scrolling).
jamone
+1  A: 

I've had the same question, and i've played with it a bit, setting a UIScrollView is not enough, as in the inspector you should 1st. increase it Hight, then in the attributes, check the following checkboxes: Scrolling enabled, Bounce Scroll, always bounce vertically.

Edited: Forgot the most inportant thing: in the size inspector, set the Buttom field (under content) to the size you wish, (960 is twice the regular size)

Dror Sabbag
Adding a UIScrollView on top of UIView is also possible (then layout all your controls on it) but you will have to do some coding as well:connect it to a UIScrollView instance, and in the viewDidLoad method, add the following: scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 3, scrollView.frame.size.height); scrollView.showsHorizontalScrollIndicator = NO; scrollView.showsVerticalScrollIndicator = NO; scrollView.scrollsToTop = NO; scrollView.delegate = self;
Dror Sabbag
Everything is pretty good when I add the UIScrollView. I have a UITextView that is the first responder. When it is inside the UIScrollView it isn't first responder anymore. Weird. Have any thoughts?
Sheehan Alam
surely you can assign it to be first responder in the viewDidLoad as well;[textField1 becomeFirstResponder];
Dror Sabbag
I have tried that. See my new question at: http://stackoverflow.com/questions/2859268/uitextview-inside-uiscrollview-is-not-first-responder
Sheehan Alam