zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    python subprocess.Popen 非阻塞
    linux错误码
    python中logging
    python多线程和多进程对比
    python多进程提高cpu利用率
    django orm 操作
    linux故障判断
    linux中软链接打包、计算以及同步
    小程序收集formid跳转后收集不到
    Git Base 操作(二)
  • 原文地址:https://www.cnblogs.com/csdnIOS/p/4164164.html
Copyright © 2011-2022 走看看