• iOS 6,5支持 portrait,landscape (横竖屏的处理)


    最近在项目中遇到iOS6的一点问题,主要是横竖屏的处理不一样了,多了一些方法,原来的方法被废弃掉了。

    可能主要是为了适配iPhone5吧。具体的原因不深究,解决问题。

    在网上找了一些解决方法,但是不适合我在项目中使用。

        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0) {

            [self.window addSubview:navController.view];

        }else{

            [self.window setRootViewController:navController];

        }

    有人建议这样修改,但是我看不到任何这么修改的依据,所以项目中并没有使用这样的方式修改,

    主要还是依赖于SDK自身的特点来进行修改吧。

    进入正题:

    主要修改以下几个方面

    在AppDelegate中增添一个方法,我这里只支持竖屏的处理,就只设置了这一种方式(可以根据自身的需要进行设置)

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

    {

        return (UIInterfaceOrientationMaskPortrait);

    }

    在viewController中增加下面的两个方法,同时保留原有的方法

    //iOS6中新增的两个方法 

    - (BOOL)shouldAutorotate

    {

        return NO;

    }

     

    - (NSUInteger)supportedInterfaceOrientations

    {

        return (UIInterfaceOrientationMaskPortrait);

    }

    //在iOS6中废弃了的方法,保留,以适配iOS4和5 

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

    {

        return toInterfaceOrientation == UIInterfaceOrientationPortrait;

    }

     

    搞定了,然后在项目中就可以支持iOS6,iOS4和5的屏幕适配了,这里主要是竖屏,大多数程序也是竖屏

    可以根据自身的需要进行修改。

     

  • 相关阅读:
    shell脚本基础
    rtsp冷门解释
    C++基础之动态内存
    树莓派3安装ros
    Trie树
    [LeetCode]The Skyline Problem
    [LeetCode]Implement Trie (Prefix Tree)
    C++基础之适配器
    配置树莓派3的openwrt中的网络
    [LeetCode]Self Crossing
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2737796.html
Copyright © 2020-2023  润新知