Sunday 18 July 2010

Autorotation and Autoresizing

Auto rotation might not be right for every application. Several apps support only a single orientation rotation.
If auto rotation enhances user experience add it to your app.
Auto rotation is specified in the view controller.
Most of the work in actually moving the pixels around the screen is managed by the iPhone OS. There are three approaches to auto rotation dependent upon the complexity of the interface. With simpler interfaces simply specify the auto resize attributes for all the objects that make up the interface.
More complex interfaces have to handle auto rotation in a different manner. One approach is to manually reposition the objects in the view when notified that the view is rotating.
The second approach is to actually design two different versions of the view in the interface builder, one for portrait mode and a seperate one for landscape mode.
In both cases need to override methods from UIViewController in view's controller class.
Add code to .m file, method already provided (commented out) called shouldAutoRotateToInterface need to uncomment and add code.
Four defined orientations in the way that the phone is held:
  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationUpsideDown
  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationLandscapeRight
When view changed this method called on active view controller. Possible for some views to support auto rotation but not others.
Upside down orientation is discouraged as the phone will remain that way if it rings. Most controls default to a setting where items on the screen stay where they are when rotated in relation to the left side and the top of the screen.






For larger items specify new positions when view is rotated to prevent overlapping. To change a control's attributes need an outlet to point to the object that needs to be changed.
The size and position of all views, including controls such as buttons are specified within a property called frame, which is a struct of type GRect. GRectMake is a function by apple that lets you easily create a GRect by specifying x and y positions along with the width and height.
GREct comes from core graphics framework.
Designing portrait and landscape view seperately and swapping in and out is a moderately complex action. Requires 2 completely distinct set of outlets one for each view. Cannot change the size of the default view.

No comments:

Post a Comment

Search This Blog