views:

48

answers:

3

I have already built a UIViewController subclass with a bunch of controls in it, and just realized that if I rotate the iPhone, half of the controls become invisible. So, I would like to somehow make the UIViewController's UIView scrollable so that when the device (or the Simulator) rotates, the user can scroll the view to see all the controls.

I was hoping to do this all in Interface Builder. I tried to change the class of the view from UIView to UIScrollView in the Class Identity editor, but nothing scrolls. The base class of my view controller is a simple UIViewController .

Is there an easy way to make the main view in my view controller scrollable without having to recreate the whole thing in IB?

+1  A: 

Add a UIScrollView and make all your controls and widgets and labels subviews of the scroll view by dragging them from wherever they are "into" or "inside" the scroll view. This makes them subviews of the scroll view, which is what you want.

Alex Reynolds
Tried this, too. Added UIScrollView, moved controls into that, removed UIView, made my controller a UIScrollViwDelegate and made controller the delegate and scrollview its view. No scroll.
Paul
A: 

It would be helpful to understand what your interface is displaying, but I'd suggest one of the following:

  1. Don't allow rotation by returning NO from shouldAutorotateToInterfaceOrientation
  2. Use Interface Builder to adjust your springs and struts so that all of your interface elements fit in landscape view
  3. Add a new UIScrollView in Interface Builder and drag your UIView into it, then re-assign the view property of your File's Owner to the scroll view.
chrispix
1. I want rotation.2. There isn't room. Trust me.3. Tried it. No scroll. Is it a delegate problem?
Paul
Have you tried updating your UIScrollView's contentSize when it rotates?
chrispix
A: 

You can init self.view with UIScrollView object

self.view = [[[UIScrolView alloc] initWithFrame:self.view.frame] autorelease];
nepo
Not sure where this would belong. In loadView? I tried something like this, but all my controls disappeared.
Paul
You can do this in init. Before you place on view other objects. Don't forget about frame!But in loadView better. - (void)loadView { self.view = [[[UIScrolView alloc] initWithFrame:self.view.frame] autorelease]; self.view.frame = CGRectMake(0, 0, 320, 460); }
nepo