PDA

View Full Version : Modelling rotation in Interface Builder




RossOliver
Jun 11, 2008, 02:34 AM
Hey,

Upon creating a new window in IB, I now notice the little arrow in the top right corner allowing rotation to be simulated. It works great for some of my views, resizing my buttons for me and what not, but on others I need to change the size of a component when it is rotated to landscape (and obviously change it back when it's rotated to portrait).

I can't see any way to create state between the two orientations - changing a component in one orientation changes it in both... is there a way to give it state in IB so it knows which way up it is and how to display a component when it is that way up?

Also, how do I get this nice rotation simulation in an XIB containing only a view (no window)?

Cheers



RossOliver
Jun 14, 2008, 11:34 AM
I take it that this can't be achieved in Interface Builder yet then? Is it likely to appear in the final release or is it something that will only every be achieved programmatically?

Sbrocket
Jun 14, 2008, 01:22 PM
Hey,

Upon creating a new window in IB, I now notice the little arrow in the top right corner allowing rotation to be simulated. It works great for some of my views, resizing my buttons for me and what not, but on others I need to change the size of a component when it is rotated to landscape (and obviously change it back when it's rotated to portrait).

I can't see any way to create state between the two orientations - changing a component in one orientation changes it in both... is there a way to give it state in IB so it knows which way up it is and how to display a component when it is that way up?

This is something you'd want to do programmatically. In truth, Interface Builder can only do simple things and whenever you need to do stuff like animation you're going to need to go back to code. This is the reason all the WWDC sessions show the code method needed in order to achieve different things rather than just dragging some objects around in IB. IB can be a useful tool (though I haven't really thought its worth in while for UIKit yet), but you always want to know how to do things programmatically and what the equivalent code would be for each of your actions in IB. It can only help you.


Also, how do I get this nice rotation simulation in an XIB containing only a view (no window)?

Cheers

UIView cannot auto-rotate - you need a UIViewController in order to catch the rotation notifications, which the UIWindow object in IB presumably creates to manage the window's view.

liptonlover
Jun 14, 2008, 01:40 PM
we're talking about an iphone window right?
You need to learn how to use the auto resize features in IB. By utilizing those options properly your buttons will behave properly when you rotate the view.