TPMultiLayoutViewController iOS

* * * * (51 ratings)
TPMultiLayoutViewController | App Code for Sale | Hero

Overview

A drop-in UIViewController subclass that automatically manages switching between different view layouts for portrait and landscape orientations, without the need to maintain view state across two different view hierarchies.

The Problem

  • You want to support portrait and landscape modes in your app.
  • Having just one view layout for both portrait and landscape doesn't give good results.

The Conventional Solution: Double Handling

  • Create two distinct view hierarchies: one for portrait and one for landscape.
  • On orientation change, set this.view to either your portrait view, or your landscape view.
  • On load, perform your initialisation on both views: Big Overhead.
  • Whenever your view/app state changes, sync the state across both views: Big Overhead.

An Easier Solution: Layout Templating

  • Create two distinct view hierarchies: one for portrait and one for landscape.
  • Extract just the layout information from the two view versions: use the original two view hierarchies as a layout template.
  • Maintain one single view hierarchy: no double handling, no state syncing.
  • On orientation change, simply apply the layout information we extracted to our single view hierarchy, to achieve the new layout.

In summary, we skip the double handling by keeping just one view, not two views we need to sync. When the orientation changes, we just rearrange the view, using the layout we extracted from our original two views.

0 Comments Leave a comment