ShrimpCrackers ShrimpCrackers - 4 years ago 307
Swift Question

iOS View does not change orientation on orientation change

I have a root view which contains a scroll view which contains a (content) view. The content view contains many child controls. Using the simulator, when I change orientation, none of the views, including the scroll view changes orientation. For example the image below starts out in portrait mode and all controls are played out correctly, but moving to landscape mode just shows portrait mode horizontally:

enter image description here

All of this was laid out using Interface Builder, so I don't have much code in the control view file besides some IB outlets to the controls.

Is there some sort of constraint that is preventing the reorientation of all the controls and views? Or do I always have to lay these out manually on orientation change?

Answer Source

First you need to check you have allowed the app to rotate by checking the orientations you want are ticked:

  • Click on the top-left corner (Show the Project Navigator)
  • Select the name of your project
  • See what is under General->Deployment Info->Device Orientation.
  • Adjust the tickboxes accordingly.

Update:

Also slide up on the simulator and check that rotation isn't locked for the device.

Try putting this in your AppDelegate/view controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:
  (UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

(I don't think it's a constraint/layout issue as the status bar isn't even rotating)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download