导航栏的内容在 iOS 13 的模式中部分不可见 [英] Navigation Bar's content partially not visible in modal on iOS 13

查看:78
本文介绍了导航栏的内容在 iOS 13 的模式中部分不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当导航栏显示在模式屏幕中时,基于故事板的应用程序在呈现导航栏的内容时出现问题,但仅限于在物理设备上时.代码在 iOS 12 和所有模拟器(包括 iOS 12 和 iOS 13.2.2)中都能正常运行.

截图左侧是运行iOS 13.2.2的iPhone 11模拟器;右侧是运行相同代码的 iOS 13.2.2 的 iPhone Xs 的 Reflector 投影.我们可以看到物理设备上的 tableview 和导航栏内容之间有一个空格,但在模拟器上,tableview 与导航栏齐平.

没有表格部分视图标题,表格视图边距设置为安全区域.有没有其他人遇到过这个问题,如果有,你是如何解决的?

这是从设备捕获的堆栈视图的快照,我们可以清楚地看到被错误渲染的区域正好在 UINavigationBar 的边缘内:

在设置以下视图结构时,我还能够在一个全新的项目中复制该问题:

运行此演示项目的代码可在 GitHub 上找到:

我们可以看到物理设备在导航栏的内容和 tableview 之间显示了一个红色的栏;但是在模拟器中看不到那个红条.

<小时>

2019-11-25 16:45 EDT -- 根据下面的评论,我尝试使用以下方法强制刷新布局:

override func viewWillAppear(_animated: Bool) {super.viewWillAppear(动画)如果#available(iOS 13.0,*){DispatchQueue.main.async {self.navigationController?.navigationBar.setNeedsLayout()self.navigationController?.navigationBar.layoutIfNeeded()}}}

有和没有调度异步,以及有和没有 layoutIfNeeded;它没有为我解决这个特殊问题.

解决方案

基于 如何防止 iOS 13 中 uinavigationbar 和 view 之间的差距?,这对我不起作用,我使用以下代码解决了我的问题:

override func viewWillAppear(_animated: Bool) {super.viewWillAppear(动画)如果#available(iOS 13.0,*){self.navigationController?.setNavigationBarHidden(真,动画:假)self.navigationController?.setNavigationBarHidden(假,动画:假)}}

或者在 Objective-C 中:

-(void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];如果(@available(iOS 13,*)){[self.navigationController setNavigationBarHidden:true 动画:false];[self.navigationController setNavigationBarHidden:false 动画:false];}}

A storyboard based application is having issue rendering the navigation bar's content when the navigation bar is displayed in a modal screen, but only when on a physical device. The code behaves properly in iOS 12 and in all simulators both iOS 12 and iOS 13.2.2.

On the left of the screenshot is a iPhone 11 simulator running iOS 13.2.2; on the right is a Reflector projection of my iPhone Xs running iOS 13.2.2 of the same code. We can see there's a space between the tableview and the navigation bar content on the physical device, but on the simulator the tableview is flush against the navigation bar.

There are no table section view headers, tableview margins are set to safe area. Has anyone else experienced that issue and if so, how did you solve it?

Here's a snapshot of the stackview captured from the device, in which we can clearly see the area being mis-rendered is well within the margins of the UINavigationBar:

I was also able to replicate the issue on a brand new project when setting up the following view structure:

The code to run this demo project is available on GitHub at: https://github.com/ekscrypto/stackoverflow-59033294

With the differing behaviours:

We can see physical device showing a bar of red between the navigation bar's content and the tableview; but that red bar is not visible in the simulator.


edit: 2019-11-25 16:45 EDT -- As per comments below I tried to force a refresh of the layout using:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    if #available(iOS 13.0, *) {
        DispatchQueue.main.async {
            self.navigationController?.navigationBar.setNeedsLayout()
            self.navigationController?.navigationBar.layoutIfNeeded()
        }
    }
}

With and without the dispatch async, as well as with and without the layoutIfNeeded; it did not solve this particular issue for me.

解决方案

Based on the answer at How to prevent gap between uinavigationbar and view in iOS 13?, which wasn't working for me, I solved my issue using the following code:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    if #available(iOS 13.0, *) {
            self.navigationController?.setNavigationBarHidden(true, animated: false)
            self.navigationController?.setNavigationBarHidden(false, animated: false)
    }
}

Or in Objective-C:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if(@available(iOS 13, *)) {
        [self.navigationController setNavigationBarHidden:true animated:false];
        [self.navigationController setNavigationBarHidden:false animated:false];
    }
}

这篇关于导航栏的内容在 iOS 13 的模式中部分不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆