Using horizontal screen for IOS

Source: Internet
Author: User

http://lizhuang.iteye.com/blog/1684881

In the ipad app development How to let the device only support horizontal screen (landscape) mode, I did a number of attempts, and did not find a relatively simple setup method. I tried about 3 different ways.
1, through the Xcode set "IPad Deployment info", only select the horizontal screen left and the horizontal screen right, after the deployment test did not take effect, this method is in essence, add the following information in the Xxx_info.plist project configuration file:
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
2, this law does not take effect by setting orientation to landscape for each nib file in ib.
3, Overload shouldautorotatetointerfaceorientation: method, this way is feasible. Specific as follows:
-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation
{
Return YES for supported orientations
Return ((interfaceorientation ==uideviceorientationlandscapeleft) | | (Interfaceorientation ==uideviceorientationlandscaperight));
}
If the first method is effective, then it is more perfect. Although the third way can fully meet the needs of the horizontal screen, but the implementation is more stupid, you need to overload shouldautorotatetointerfaceorientation in each controller: method, It is also possible to avoid repetitive work by extending uiviewcontroller. But it also feels a bit less straightforward, expecting someone to point out whether the SDK itself has a simple way to support it.

ipad interface layout A lot of time to do two sets of------horizontal screen and vertical screen, but in the interface switch, which layout should be judged, there are many ways, I recorded the one I used, feel more convenient:
Nsnotificationcenter *NC = [Nsnotificationcenter defaultcenter]; GET the notification centre for the app
[NC addobserver:self//add yourself as an observer
Selector: @selector (orientationchanged)
Name:uideviceorientationdidchangenotification
object:nil];//This function to get the direction of the current device,
-(void) orientationchanged
{
UIView *ftview = [Self.view viewwithtag:200];
if ([[Uidevice currentdevice] orientation] = = Uideviceorientationlandscapeleft | | [[Uidevice currentdevice] orientation] = = uideviceorientationlandscaperight)//judgment about
{
New layout of the interface
}
if ([[[Uidevice currentdevice] orientation] = = uiinterfaceorientationportrait)//I have a direction is not supported, if you want to support it then do not have the IF condition on the line
{
New layout of the interface
}
}

The real machine has been tested on IOS 5. Very convenient, use later can realize, here not more said!

Using horizontal screen for IOS

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.