Problems with screen orientation during iOS development

Source: Internet
Author: User

There are a lot of ways to judge the screen and only a few of the options that I personally think are useful.

Landscape Vertical Screen Portrait The most effective way is: In the Willrotatetointerfaceorientation:duration: method to store the direction: Drviceorientation = Tointerfaceorientation; Then use the appropriate screen orientation method in another method: The method of acquiring the device directly: Self.interfaceorientation (this method has expired) method two: The following method: uideviceorientation duration = [[ Uidevice Currentdevice]orientation]; Method 1, 2 when running in the emulator, the device orientation that was just started is the Unknow method three followed by the width of the screen to calculate the corresponding screen direction [[Uiscreenmainscreen] Applicationframe].size.height[[uiscreenmainscreen] Applicationframe].size.width can be used to get the current screen size, height and width. Since the system's status bar is 20 high and always on top of the screen, it makes the above two values change in the vertical and horizontal screen, so it can be used to determine whether the current is a flat screen or portrait screen. The height of the 1004,width is 768 when it is simple to say vertical screen. At the horizontal screen, the height is 1024,width to 748. Of course, if you don't remove the system's status bar. It can be used in any method as a judging condition. The application example is as follows: if (Loadingview ==nil) {loadingview = [[Uiviewalloc] initWithFrame:    CGRectMake (284, 402, 200, 200)]; if ([[[Uiscreenmainscreen] applicationframe].size.height==1024) {loadingview.frame=cgrectmake (412, 264, 200, 200 );//This is horizontal screen} [Loadingviewsetbackgroundcolor:[uicolorclearcolor]];} When creating the Loadingview, set the position according to the current screen. Method Four has already been sent in the forum (I have only done a simple handling work here)//The following is directly in the screen direction to determine-(void) WillanimaterOtationtointerfaceorientation: (uiinterfaceorientation) interfaceorientation Duration: (nstimeinterval) Duration {    Switch (interfaceorientation) {caseuiinterfaceorientationportrait://home is alive under break;    Caseuiinterfaceorientationportraitupsidedown://home alive on break;    Caseuiinterfaceorientationlandscapeleft://home alive left break;    Caseuiinterfaceorientationlandscaperight://home Alive Right break;       Default:break; } method five re-screen rotation when the screen is recorded in the direction of the painting needs to start after the window to allow the screen to rotate, or the painting when the program starts when the direction of the screen will be a problem #pragma mark screen rotation complete-(void) Didrotatefrominterfaceorientation: (uiinterfaceorientation) frominterfaceorientation{NSLog (@ "screen rotates to complete dockview height%f    ", self.dockView.height); Self.dockView.width = Self.dockwidth;} #pragma mark screen will rotate-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation duration :(nstimeinterval) duration{[UIView animatewithduration:0.25 animations:^{self.dockView.width = Self.dock    Width; }];        Determine the horizontal screen if (uiinterfaceorientationisportrait (tointerfaceorientation)) {NSLog (@ "screen will be rotated to portrait screen");    Self.dockView.width = Self.dockwidth;        }else{NSLog (@ "screen will be rotated to horizontal screen");    Self.dockwidth = 100; }}



Problems with screen orientation during iOS development

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.