Landscape uiviewcontroller/uiview rotation/only supports landscape screens

Source: Internet
Author: User

1. In the "info. plist" file, setting the following property:

Code:
<key>UIInterfaceOrientation</key>    <string>UIInterfaceOrientationLandscapeRight</string>


2. In the "applicationdidfinishlaunching" of the app delegate, calling the following code:

Code:
// Make the window active[window makeKeyAndVisible];// Now try to set the orientation to landscape (right)[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

3. Finally, implementing this method in the View Controller:

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);}


This gets me very close... it is a little hard to describe what it does, but heres goes nothing:

1. The application launches with the status bar in landscape, but the rest of the screen is black.
2. The view then appears (it is an eaglview), but in portrait.

3. The view immediately rotates to the proper landscape orientation with the animation is if the user had rotated the device.

 

 

 

If you're looking to rotate your uiview programmatically, instead of when the phone physically changes orientation... try this code in your uiview or uiviewcontroller:

Code:
// Rotates the view.CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);self.view.transform = transform;// Repositions and resizes the view.CGRect contentRect = CGRectMake(-80, 80, 480, 320);self.view.bounds = contentRect;

View rotation uses radians instead of degrees... so a 90 degree rotation is PI/2 (Thank God Wikipedia has an article on radians !)

When you rotate the view, if you don't resize and reposition it... you'll find that it's origin point (it's top left corner with the phone held landscape style) is at the top edge, but about a half an inch indented. the result is there is a chunk of the screen on the left and right that is not touchable. resizing and repositioning fixed that for me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.