zoukankan      html  css  js  c++  java
  • ios7之后的一些更改

    //定义宏,判断ios7
    #define IOS7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0
    if (iOS7) {
            self.automaticallyAdjustsScrollViewInsets = NO;
            self.edgesForExtendedLayout = UIRectEdgeNone;
        }

    1、self.automaticallyAdjustsScrollViewInsets = NO;
    看 这个UIViewController的这个属性你就明白了,此属性默认为YES,这样UIViewController下如果只有一个 UIScollView或者其子类,那么会自动留出空白,让scollview滚动经过各种bar下面时能隐约看到内容。但是每个 UIViewController只能有唯一一个UIScollView或者其子类,如果超过一个,需要将此属性设置为NO,自己去控制留白以及坐标问 题。

    2、在iOS 7中,苹果引入了一个新的属性,叫做[UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll。当你的容器是navigation controller时,默认的布局将从navigation bar的顶部开始。这就是为什么所有的UI元素都往上漂移了44pt。

    [UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll。当你的容器是navigation controller时,默认的布局将从navigation bar的顶部开始。这就是为什么所有的UI元素都往上漂移了44pt。

    - (void)viewDidLoad中添加如下一行代码:

    1
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    

    这样问题就修复了。

    3、iOS7view默认是全屏模式,状态栏的高度也加在了view的高度上,例如iOS7之前iphone5self.view.frame.size.height = 548,在iOS7中就是568

    如果要push很多页面,可以这样全局设置:

    /**
     *  拦截所有push进来的控制器
     *
     *  @param viewController 即将push进来的控制器
     */
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        if (iOS7) {
            viewController.edgesForExtendedLayout = UIRectEdgeNone;
        }
        if (self.viewControllers.count > 0) { // 这时push进来的控制器viewController,不是第一个子控制器(不是根控制器)
            /* 自动显示和隐藏tabbar */
            viewController.hidesBottomBarWhenPushed = YES;
            /* 设置导航栏上面的内容 */
            // 设置左边的返回按钮
            viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:@"arrow_left" highImage:@"arrow_left"];
            
    //        [viewController.navigationController.navigationBar setBarTintColor:HLGeneralColor];
            
            // 设置右边通用按钮
    //        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(general) image:@"navigationbar_general" highImage:@"navigationbar_general_highlighted"];
            
            [(HLTabBarController *)([UIApplication sharedApplication].delegate).window.rootViewController hideBottomBar:YES];
            
            viewController.view.backgroundColor = HLGrayBackgroundColor;
    
        }

    这样所有push过去的页面都会执行上面的代码。

    也可以让所有将要push的控制器继承一个BaseViewController,在里面的ViewDidLoad 里面设置

    if (iOS7) { viewController.edgesForExtendedLayout = UIRectEdgeNone; }

    待续。。。

  • 相关阅读:
    Java基础:基本类型
    完全干净的卸载VS2013
    git本地仓库首次push到远程仓库出现错误 ! [rejected] master -> master (fetch first)
    运行VS出现warning C4996错误的解决办法
    xbmc-android的编译
    linux执行sh,出现/bin/sh^M: bad interpreter: No such file or directory
    Ubuntu配置android-vlc编译环境(2015-11-05)
    a80修改默认4k输出,官方代码锁死了
    ubuntu12.04平台下a80编译环境搭建
    编译java代码出现 错误: 需要class, interface或enum 提示
  • 原文地址:https://www.cnblogs.com/zpt1011/p/5312465.html
Copyright © 2011-2022 走看看