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