美文网首页
导航及statusBar小知识

导航及statusBar小知识

作者: Auther丶 | 来源:发表于2016-11-24 14:48 被阅读31次

    iOS 11 没有这种问题

    1.通话或录音时 打开某一App 此时状态栏frame.height 会从20 增加为40,applicationFrame.height 会减少20.

    新创页面:
    如果没有用autolayout 在布局的时候可以用 [UIScreen mainScreen].applicationFrame 代替 [UIScreen mainScreen].bounds。bounds为整个屏幕的尺寸 ,applicationFrame 为 减去statusBar之后的高度. 例如 :bounds:{0,0,320,480} applicationFrame:{0,20,320,460} - normal {0,40,320,440} - in-call 。

    页面已创建:
    如果没有使用autolayout 在页面创建后 接打电话 可以通过VC的方法
    – (void)viewWillLayoutSubviews 来拿到最新的view.frame 然后更新子控件布局,适应高度减少的20。

    也可以通过监听statusBar 变化来更新控件

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

    UIApplicationWillChangeStatusBarFrameNotification 监听得到改变后的新 frame
    UIApplicationDidChangeStatusBarFrameNotification 监听得到改变前的旧 frame

    利用 触发 selector 中传入的 notification参数,即
    NSValue *rectValue = [noti.userInfo objectForKey:UIApplicationStatusBarFrameUserInfoKey] 获得监听到的新/旧 frame.

    相关文章

      网友评论

          本文标题:导航及statusBar小知识

          本文链接:https://www.haomeiwen.com/subject/hivbpttx.html