• ios开发强制横竖屏转换


    第一种:手动的设置界面元素的旋转,包括状态栏、导航栏和视图。以下代码为从竖屏设置为横屏,坐标系是以竖屏的为基准,所以会出现负数的坐标值。

        //设置状态栏旋转

        [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeRightanimated:YES];

        CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;

        //设置旋转动画

        [UIView beginAnimations:nil context:nil];

        [UIView setAnimationDuration:duration];    

        //设置导航栏旋转

        self.navigationController.navigationBar.frame = CGRectMake(-204, 224, 480, 32);

        self.navigationController.navigationBar.transform = CGAffineTransformMakeRotation(M_PI*1.5);

        //设置视图旋转

        self.view.bounds = CGRectMake(0, -54, self.view.frame.size.width, self.view.frame.size.height);

        self.view.transform = CGAffineTransformMakeRotation(M_PI*1.5);

        [UIView commitAnimations]

    第二种切换到下一个页面强制转横屏

            if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {

                SEL selector = NSSelectorFromString(@"setOrientation:");

                NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];

                [invocation setSelector:selector];

                [invocation setTarget:[UIDevice currentDevice]];

                int val = UIInterfaceOrientationLandscapeRight;

                [invocation setArgument:&val atIndex:2];

                [invocation invoke];

            }

    这有一个很好的小demo,大家可以看下http://www.cocoachina.com/bbs/read.php?tid=143978

  • 相关阅读:
    Newton's Method in C#
    bat中的注释符
    Oracle query and backup
    Oracle Essentials
    修改Oracle 10g数据库字符集
    Some awareness before migrating from x86 to x64
    DataTable 那些事(二)
    很赞的PHP字符串加密函数
    PayPal 注册和使用详解
    ASP网站session超时,后台操作超时,重新登陆
  • 原文地址:https://www.cnblogs.com/csdnIOS/p/4164164.html
Copyright © 2020-2023  润新知