iOS supports horizontal screen rotation, general methods and forced selection

Source: Internet
Author: User

Horizontal Screen SupportGeneral methods Support rotation
// does the controller's content support automatic rotation - (BOOL)    shouldautorotate{return  YES;}
    1. Simulator iOS7.1: When the screen is turned, it is called, and a horizontal screen to a vertical screen is also called.

    2. Simulator iOS8.0: When the screen is turned, it is called; horizontal screen to vertical screen, not called.

    3. Simulator iOS9.0: When the screen is turned, it is called, and a horizontal screen to a vertical screen is also called.

      http://stackoverflow.com/questions/26503423/shouldautorotate-behavior-in-ios-8

// all user interface orientations supported by the controller - (uiinterfaceorientationmask)  supportedinterfaceorientations{  return  Uiinterfaceorientationmaskall;}
When the user changes the orientation of the device, the system invokes the root view controller or the view controller's method shown. If the view controller supports a new orientation, the window and view controller will rotate to the new direction. This method is not called when Shouldautorotate is set to No.
// Show direction of view Controller - (uiinterfaceorientation) preferredinterfaceorientationforpresentation{   return  uiinterfaceorientationportrait;}
This method is called when the View controller is displayed in full screen, giving priority to the direction of the view controller based on the direction you set.

If this method is not implemented, the system determines the direction of the view controller based on the direction of the current status bar.

Force Setting the Orientation property value

The official web orientation is a read-only attribute. We can't rewrite its value directly. But

Before iOS5: SetOrientation can change the value of the Orientation property.

[[Uidevice Currentdevice] setorientation:uiinterfaceorientationlandscaperight];

However, after iOS6, this method is deprecated, but we can also use the following method to strong screen orientation.

[ [Uidevice Currentdevice] SetValue:                      [nsnumber numberwithinteger:uiinterfaceorientationportrait]                            Forkey:@ "orientation"];

In fact, these two methods let you get or set the properties of any object:
-(ID) Valueforkey: (NSString *) K; -(void) SetValue: (ID) v forkey: (NSString *) K;

This is KVC (key value encoding) is implemented through a series of methods defined in NSObject, and we can access the value of the property through the name of the property.

Http://stackoverflow.com/questions/18035992/objective-c-setvalueforkey-on-c-primitive-types

Https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/BasicPrinciples.html

iOS supports horizontal screen rotation, general methods and forced selection

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.