Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify an existing UIViewController to allow scrolling?

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 <UIScrollViewDelegate>.

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

like image 329
Paul Avatar asked Jul 07 '10 04:07

Paul


2 Answers

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.
like image 105
Christopher Pickslay Avatar answered Sep 22 '22 12:09

Christopher Pickslay


For people who are using storyboard, this is quite easy to do

  • in Document Outline select the topmost View of the UIViewController
  • then in Identity Inspecter, under Custom Class, for class enter UIScrollView

That's it.

like image 42
Konsol Labapen Avatar answered Sep 22 '22 12:09

Konsol Labapen