1

I'm using storyboards and need to create to different views for portrait and landscape layout. I can't use auto layout in this case because I need to completely rearrange things in some cases.

I found a solution to use two different views and hide or show it depending on the device orientation but it doesn't work very good for me. I have a lot of outlets that I need to connect from xcode designer to code, and it seems that I can't connect two diffrents objects like for example two different buttons to the same IBOutlet. Can I? When I did this only one was really working. Moreover this solutions doesn't seem so efficient.

I took also a different approach and created two different view controllers which I load according to the device orientation, but there's a problem when for example I turn off application change orientation of the device and turn on it again and come back to a view controller that was in the beginning of the navigation stack, then it has an orientation that it has before.

Anyone has some ideas how to solve this problem?

Wojtek
  • 1,006
  • 11
  • 30

1 Answers1

0

You should only use one ViewController and one view and kind of hard-code the positions of the elements. Like (pseudocode)

if (orientation landscape) label1.frame = ...

else (orientation portrait) label1.frame = ...

Maybe you can group parts of the layout within another UIView (select the elements and go in Xcode->Editor Menu->Embed->View. Then connect the new view to the ViewController and push it where you need it.

Take a look at this answer, maybe it helps

Community
  • 1
  • 1
brainray
  • 12,512
  • 11
  • 67
  • 116