As you well know, by default, iPhone applications launch in portrait mode. If you need to start your application in landscape mode, you can set UIInterfaceOrientation key in the plist file. The two possible values for this key are: UIInterfaceOrientationLandscapeLeft (iPhone home button will be on the left) and UIInterfaceOrientationLandscapeRight (home button on right).
For views to be shown in landscape mode, you must manually rotate the coordinate system 90 degrees. Here’s one way you can do that, let’s assume we have a class that is of typeUIViewController:
Inside the implementation file of SomeViewController, here’s one approach you can use within the viewDidLoad method:
Specifying CGAffineTransformMakeRotation call with 90 degrees as shown above will show the view in the UIInterfaceOrientationLandscapeRight. Setting this value to -90 will show the view in the UIInterfaceOrientationLandscapeLeft.
If you set the orientation in the plist file, you’ll need to coordinate the value set in the loadViewmethod so the status bar appears as expected, that is, across the top of the display. If you choose set the orientation in the plist as UIInterfaceOrientationLandscapeLeft, use -90 as the rotation value, set to 90 for UIInterfaceOrientationLandscapeRight.
There are more ways than one to rotate views to landscape mode, if you have a preferred means, please post a comment.
No comments:
Post a Comment