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];

  • 相关阅读:
    一张一驰,文武之道
    关于“未能加载……”和“web.config”
    DotText学习心得_1
    windows服务与事务
    AWR报告生成
    Java EE启示录
    跨入安全的殿堂读《Web入侵安全测试与对策》感悟
    用VS2005写Loadrunner测试脚本
    List of Free Programming books
    硬盘基础知多少
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3188444.html
Copyright © 2011-2022 走看看