zoukankan      html  css  js  c++  java
  • iPhone/iOS开启个人热点的相关位置调整小结

        冬至已到,圣诞将近,最近公司项目实在太多,三四个项目反复的切换真的让人焦头烂额,趁今天有点空,把维护的三个项目顺利送出,刚好可以缕缕思路,记录一下最近遇到的问题。说不着急那是假的,客户一天天的催的确实令人心烦意乱,但是回过头来想想也确实不易,所以还是说服自己认真对待他们反馈的一个个问题,尽量做到让他们满意也让自己满意。有句话怎么说来,终于完成了,还好我没放弃。哈哈,闲言不多讲,说一下最近遇到解决的一个问题吧,由热点引起状态栏位置变化而导致自定义底部栏位置错位的问题。

        关于热点的帖子网上确实不少,也给了很多的解决的方案。iPhone作为个人热点且有连接时,系统状态栏下面会多一行热点连接提示栏"Personal Hotspot: * Connection",纵向会下压20pt;当所有连接都断开时,热点栏消失,纵向高度恢复正常。

    1.系统状态栏

    APP_STATUSBAR_HEIGHT=[UIApplication sharedApplication].statusBarFrame.size.height,包含热点栏(如有)高度,标准高度为20pt,当有个人热点连接时,高度为40pt

    // iOS系统版本

     

    #define SYSTEM_VERSION    [[[UIDevice currentDevice] systemVersion] doubleValue]

     

    // 标准系统状态栏高度

    #define SYS_STATUSBAR_HEIGHT                        20
    // 热点栏高度
    #define HOTSPOT_STATUSBAR_HEIGHT            20
    // 导航栏(UINavigationController.UINavigationBar)高度
    #define NAVIGATIONBAR_HEIGHT                44
    // 工具栏(UINavigationController.UIToolbar)高度
    #define TOOLBAR_HEIGHT                              44
    // 标签栏(UITabBarController.UITabBar)高度
    #define TABBAR_HEIGHT                              44
    // APP_STATUSBAR_HEIGHT=SYS_STATUSBAR_HEIGHT+[HOTSPOT_STATUSBAR_HEIGHT]
    #define APP_STATUSBAR_HEIGHT                (CGRectGetHeight([UIApplication sharedApplication].statusBarFrame))
    // 根据APP_STATUSBAR_HEIGHT判断是否存在热点栏
    #define IS_HOTSPOT_CONNECTED                (APP_STATUSBAR_HEIGHT==(SYS_STATUSBAR_HEIGHT+HOTSPOT_STATUSBAR_HEIGHT)?YES:NO)
    // 无热点栏时,标准系统状态栏高度+导航栏高度
    #define NORMAL_STATUS_AND_NAV_BAR_HEIGHT    (SYS_STATUSBAR_HEIGHT+NAVIGATIONBAR_HEIGHT)
    // 实时系统状态栏高度+导航栏高度,如有热点栏,其高度包含在APP_STATUSBAR_HEIGHT中。
    #define STATUS_AND_NAV_BAR_HEIGHT                    (APP_STATUSBAR_HEIGHT+NAVIGATIONBAR_HEIGHT)

    2.UIViewController.view.bounds.height

    • SYSTEM_VERSION < 7.0,UIViewController.view.bounds.height包含导航栏高度,不包含系统状态栏高度,也不包含热点栏(如果有)。
    • SYSTEM_VERSION ≥ 7.0,UIViewController.view.bounds.height包含标准系统状态栏高度和导航栏高度,但不包含热点栏(如果有)。

    也即当有热点栏时,UIViewController.view.bounds.height都自动扣除了热点栏的高度,iOS<7.0不包含标准系统状态栏,iOS≥7.0包含标准系统状态栏。
    由于iOS7把整个屏幕高度(包括状态栏,不包括热点栏)都作为了视图控制器的有效高度,因此从iOS6升级到iOS7时,会出现视图整体上移了一个状态栏的高度(20pt),并和上层的状态栏交叠在一起。

        上面的这两段是借用的他们总结的一些说明性的东西,分析的还很详细,原理还是要懂得,以后遇到问题一定要学会总结,不然的话太容易遗忘。网上给了一些解决的思路,我参考了比较好的两篇博客,他们给的思路还是挺好的,但是还需要加一些处理和判断,下面我说一下解决问题的完整过程吧。正常来说热点引起的状态栏位置的调整有两种情况,一个是当前页面已经创建打开,另一个情况是页面尚未创建,下面来专门区分一下。

      1、状态栏变化通知的处理和添加UIApplicationWillChangeStatusBarFrameNotification,UIApplicationDidChangeStatusBarFrameNotification是状态栏变化会走的两个通知,可以在

    - (void)viewWillAppear:(BOOL)animated

    {

        [super viewWillAppear:animated];

        [self.navigationController.navigationBar setHidden:YES];

        

        [[ NSNotificationCenter defaultCenter ] addObserver : self selector : @selector (statusBarFrameWillChange:) name : UIApplicationWillChangeStatusBarFrameNotification object : nil ];

        

        [[ NSNotificationCenter defaultCenter ] addObserver : self selector : @selector (layoutControllerSubViews:) name : UIApplicationDidChangeStatusBarFrameNotification object : nil ];

        

        

        CGRect statusBarRect = [[UIApplication sharedApplication] statusBarFrame];

        

        if (statusBarRect.size.height == 40)

        {

            [mytable setFrame:CGRectMake(0, -20, 320, UI_View_Hieght+64-58)];

            

            [bottomView setFrame:CGRectMake(0,UI_View_Hieght+64-58-20,320, 58)];

        }

        else

        {

            [mytable setFrame:CGRectMake(0, 0, 320, UI_View_Hieght+64-58)];

            

            [bottomView setFrame:CGRectMake(0,UI_View_Hieght+64-58,320, 58)];

        }

        

        

    }

    经过反复的测试发现,原来通知只会在页面已经创建打开这种情况下走,所以需要注册监听状态栏的通知,并作处理

    #pragma mark-状态栏录音或通话状态通知

    -(void)layoutControllerSubViews:(NSNotification *)notification

    {

        //[UIApplication sharedApplication].statusBarFrame.size.height=20;

        

        

        CGRect statusBarRect = [[UIApplication sharedApplication] statusBarFrame];

        

        if (statusBarRect.size.height == 40)

        {

            [mytable setFrame:CGRectMake(0, -20, 320, UI_View_Hieght+64-58)];

            

            [bottomView setFrame:CGRectMake(0,UI_View_Hieght+64-58-20,320, 58)];

        }

        else

        {

            [mytable setFrame:CGRectMake(0, 0, 320, UI_View_Hieght+64-58)];

            

            [bottomView setFrame:CGRectMake(0,UI_View_Hieght+64-58,320, 58)];

        }

    }

     

    - (void)statusBarFrameWillChange:(NSNotification*)notification

    {

        //[self hideTabbar:self.statusBarHidden animated:YES];

        

        //[[UIApplication sharedApplication] setStatusBarHidden:YES];

        CGRect statusBarRect = [[UIApplication sharedApplication] statusBarFrame];

        

        if (statusBarRect.size.height == 40)

        {

            [mytable setFrame:CGRectMake(0, -20, 320, UI_View_Hieght+64-58)];

            

            [bottomView setFrame:CGRectMake(0,UI_View_Hieght+64-58-20,320, 58)];

        }

        else

        {

            [mytable setFrame:CGRectMake(0, 0, 320, UI_View_Hieght+64-58)];

            

            [bottomView setFrame:CGRectMake(0,UI_View_Hieght+64-58,320, 58)];

        }

        

    }

    另一种情况就是页面尚未打开前,热点已经连接,这样的话打开页面是不会走通知的地方,需要在

    - (void)viewWillAppear:(BOOL)animated 加上上面的处理,和通知里面的代码是一样的,两个都是必须的,这样的话经过反复测试确实效果还是不错的,今天就说到这里吧先,思路终于清晰了也。

  • 相关阅读:
    路径变量@PathVariable/请求参数@RequestParam的绑定以及@RequestBody
    JSR303后端校验详细笔记
    创建ssm项目步骤
    利用 R 绘制拟合曲线
    在 Linux 中将 Caps 根据是否为修饰键分别映射到 esc 和 Ctrl
    Master Transcription Factors and Mediator Establish Super-Enhancers at Key Cell Identity Genes
    Genomic Evidence for Complex Domestication History of the Cultivated Tomato in Latin America
    Variation Revealed by SNP Genotyping and Morphology Provides Insight into the Origin of the Tomato
    The genetic, developmental, and molecular bases of fruit size and shape variation in tomato
    微信支付jsapi
  • 原文地址:https://www.cnblogs.com/bigant9527/p/5067434.html
Copyright © 2011-2022 走看看