Autolayout - different Layouts for Portrait and Landscape

4f672bf7a09a856910f318e61cdc2a4c?s=47 Pit Garbe
January 15, 2014

Autolayout - different Layouts for Portrait and Landscape

A way to make Autolayout show different layouts depending on the current orientation. Complete with animated transitions ;)

The GitHub sample project: https://github.com/leberwurstsaft/ALPlayGround

If your rather want animated slides (includes a demo video), get the Keynote here: http://d.pr/f/EDSI

4f672bf7a09a856910f318e61cdc2a4c?s=128

Pit Garbe

January 15, 2014
Tweet

Transcript

  1. AutoLayout Pit Garbe ! CocoaHeads Dresden, 14.01.2014 A few hints

  2. Separate Layouts for Portrait and Landscape

  3. Rotation - Desired Behaviour

  4. Rotation - Desired Behaviour

  5. Rotation - Probable Behaviour

  6. Rotation - Probable Behaviour

  7. The Solution 1. 2. ♥

  8. A (real) Solution •Add constraints for one orientation completely in

    IB •Add constraints, that ONLY exist in this orientation but NOT in the other to an IBOutletCollection •in -updateConstraints create the constraints for the other orientation (once) •then, depending on the current orientation, remove the old constraints and install the others
  9. Select relevant constraints Constraints concerning the inner layout inside the

    green subview Constraints concerning the layout of the green and orange subviews
  10. Put them all into an IBOutletCollection

  11. Also add IBOutlets for the important views and an array

    for the constraints that are going to be created in code.
  12. in -updateViewConstraints create all the constraints for Landscape orientation (once)

  13. Depending on the orientation, remove the old constraints and install

    the needed constraints. The changes to the frames will automatically animate. GitHub: https://github.com/leberwurstsaft/ALPlayGround
  14. None
  15. Magical Solution (not AutoLayout) •TPMultiLayoutViewController •http://atastypixel.com/blog/seamlessly-manage- portrait-and-landscape-view-controller-layouts/ •https://github.com/michaeltyson/ TPMultiLayoutViewController •

    2 years old, doesn’t know about AutoLayout and doesn’t fully cover Springs+Struts (but it works) • Improved fork (Animations, etc.) •https://github.com/amolloy/ TPMultiLayoutViewController
  16. Also worth watching