Nirav Bhatt
Nirav Bhatt

Reputation: 6969

How to support both Portrait and Landscape mode - reusable view with XIBs

I am new to orientation changes using XIBs.

I saw many questions like this, and this, but I can't seem to find simple solution here. I don't want to use any 3rd party framework that will do it, but would rather have step by step way of how should I redesign my XIBs and/or how should I create outlets. And what all should go inside XIB view code (the UIView derivative).

The view XIB don't have any outlets so far and I am not sure which outlets I should provide. Here is the structure of XIB:

enter image description here

Like the above, I would have 2-3 more XIBs from which I load views, all into same view controllers.

Again, I know how UIViewController can respond to orientation change (preferredInterfaceOrientationForPresentation and shouldAutorotateToInterfaceOrientation), but do not know how to load respective XIB with proper outlets upon each of such events. ,

Upvotes: 0

Views: 684

Answers (1)

Ryan
Ryan

Reputation: 160

This can be a pretty tricky task. You are correct that you add outlets to your views, and rearrange them programmatically in the view controller. That is a pretty daunting task, and takes a lot of time.

I would suggest using the auto layout tools provided in XCode to make this job easier, and help to make transitions look a lot smoother. Please check the links below:

Reloading the entire XIB every time the user changes orientation can be a good option if you are changing the contents of the view whenever the user changes orientation, not just the arrangement. Take a look at Apples documentation on supporting multiple Interface Orientations.

I hope this helps :)

Upvotes: 2

Related Questions