Cocos2d sets the default screen direction

Source: Internet
Author: User

The running result screens of new projects created in cocos2d are both horizontal and control code.

[Cpp]
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation
{
Return UIInterfaceOrientationIsLandscape (interfaceOrientation );

}


This code controls the default horizontal display of the screen view;

Another difference is that the direction of the hardware device (the gray-black background indicates that the device is selected and the supported direction)


When you rotate the device direction, you find that when the screen is vertical, the content in the view is not adjusted, and the tag HelloWord is not placed horizontally.

 


If you want to set the default portrait screen during running, modify the code return value (or return YES)
[Cpp]
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation
{
// Return UIInterfaceOrientationIsLandscape (interfaceOrientation );
Return UIInterfaceOrientationIsPortrait (interfaceOrientation );
}

The device support is required for the first two items. The other two items can be selected if needed;


UIInterfaceOrientationIsPortrait and UIInterfaceOrientationIsLandscape macro definition in UIApplication. h file

# Define UIInterfaceOrientationIsPortrait (orientation) = UIInterfaceOrientationPortrait | (orientation) = UIInterfaceOrientationPortraitUpsideDown)

# Define UIInterfaceOrientationIsLandscape (orientation) = UIInterfaceOrientationLandscapeLeft | (orientation) = UIInterfaceOrientationLandscapeRight)

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.