zoukankan      html  css  js  c++  java
  • ios 6 横竖屏转换

               xcode 版本4.5     模拟器:6.0

    项目需求:刚进去界面横屏,从这个界面进去的界面全是竖屏。

    程序的根控制器用了UINavigationController。下面是代码:

    1.在appdelegate中添加代码:

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

    {

        returnUIInterfaceOrientationMaskAll;

    }

    2.给 UINavigationController添加个category,在实现文件中添加如下代码:

    -(BOOL)shouldAutorotate

    {

        return [[selftopViewController] shouldAutorotate];

    }


    -(NSUInteger)supportedInterfaceOrientations

    {

        return [[selftopViewController] supportedInterfaceOrientations];

    }


    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

    {

        return [[selftopViewController] preferredInterfaceOrientationForPresentation];

    }

    3.在需要横屏的地方添加(竖屏可以更换方向):

    -(NSUInteger)supportedInterfaceOrientations{

        

        returnUIInterfaceOrientationMaskLandscapeRight// 可以修改为任何方向

    }

    -(BOOL)shouldAutorotate{ 

        returnYES;

    }


    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

        return interfaceOrientation == UIInterfaceOrientationLandscapeRight;

    }

    4.最重要的是:页面之间切换不能用导航控制器切换,必须使用:

    [selfpresentViewController:navigationController animated:YEScompletion:Nil];

  • 相关阅读:
    Spring AOP概念理解 (通俗易懂)
    分享一下几个关于ssm及spring原理的专栏链接
    liux高级常用命令
    Linux基础常用命令
    SP1716 GSS3
    HDU6579 Operation
    CF1205C Palindromic Paths
    CF1213G Path Queries
    CF1213F Unstable String Sort
    CF1213E Two Small Strings
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3188444.html
Copyright © 2011-2022 走看看