¿Qué encontrarás en este post?
ToggleRotatingViewController
Sometimes you may want to display a different view in landscape and portrait mode. A good example is Apple’s Calculator: it switches from normal in portrait mode to scientific in landscape mode.
There are several reasons you may want to do so:
- Your view is very complex and it’s impossible or very difficult to reuse it in landscape mode.
- You wish to use the extra horizontal space on the landscape mode to display new features. Apple’s Calculator app is a good example.
- You are using a sub view that takes up too much space in landscape, such as a UIPickerView.
Another app that uses this in an interesting way is WeighBot, which displays different graphics depending on the orientation.
I’m not sure which solution TapBots or Apple used for this. Mine was to create a new controller of controllers (a controller that controls other controllers), inspired by UINavigationController and friends.
FRRRotatingViewController
FRRRotatingViewController will handle the VC switching _automagically_ for you: just initialize it with 2 FRRViewControllers
and it will do the magic for you.
[crayon lang="Objective C"] -(FRRRotatingViewController *) initWithLandscapeViewController: (FRRViewController *) landscape andPortraitViewController: (FRRViewController *) portrait; [/crayon]
In the images below, a FRRRotatingController switches between two simple VCs that display an image:
Both sub view controllers can be delegated and be notified when the FRRRotatingViewController switches sub view
controllers.
Source Code
The source code is available at GitHub.