views:

2066

answers:

4

I have a view that supports landscape and portrait viewing, with the controls all moving around when you switch from one to the other. I'm currently doing this by setting the .center of each one of my controls when the user rotates the phone. The problem is that this is tedious, and requires a lot of code, and seems to defeat the purpose of using Interface Builder in the first place.

My question is: is there a way in Interface Builder for one view to support multiple looks (one for landscape one for portrait)? If not how do other people do this with IB? Do you set up 2 views?

Edit: Just to clarify my landscape and portrait views look different, I don't want a straight transform, I actually display the data differently in landscape mode

A: 

I'm not 100% sure if it's possible, but have you considered using different view controllers for landscape and portrait?

Colin Barrett
@Colin: How would that work? On a rotate I would have to drop one and add the other, which I think would do weird things with the screen refresh...it would also mean I'd have to set up some common parent class and try to make them share code...could get very messy
rustyshelf
A: 

Reviving an old post. Rusty, did you find a solution for this?

lostInTransit
I hand coded it all, and gave up on IB. So when the view rotates I reposition all the elements I need to by doing element.frame = xxx;
rustyshelf
+1  A: 

When necessary, I add UIView objects to the view in IB which I make hidden. Give it a nice background color so you can see it, and send it all the way to the background. Then use that view's frame when you need to set the frame of an object. If you have a lot of them, you might consider using UILabel instead, so you can give it a visible name in IB.

If you're worried about memory issues, just remove all these extra UIViews in ViewDidLoad and just store their frame values in member CGRects. This only works of course if you don't have any of the views auto-resize or reposition on rotate, which you probably shouldn't anyway, in this case. I do this for resizing/repositioning for any reason, not just when the screen rotates.

Ed Marty
A: 

The AutoSize attributes of IBOutlet objects in the Size Inspector of IB (command 3) give some pretty nice options for auto-stretching and positioning of items. You can control L/R and T/B screen positions and relative width and height. You can't get full control of the layout, but most of the basic operations are there.

Arrel