如何在 Swift/iOS 中将静态表视图控制器单元格约束到安全区域 [英] How to constrain static table view controller cells to Safe Area in Swift/iOS

查看:36
本文介绍了如何在 Swift/iOS 中将静态表视图控制器单元格约束到安全区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有静态单元格的表视图控制器.我在 iPhone X 上运行,滚动时,单元格似乎在导航栏和不安全区域的后面.首选的是不安全区域中的纯橙色,而不是下面显示的图像.这可能吗?我无法移动到视图控制器内的表格视图,然后我会将其限制在安全区域,因为我的单元格是静态的.

I have a table view controller with static cells. I’m running on iPhone X and when scrolling, the cells appear to be behind the navigation bar and unsafe area. What is preferred would be a solid orange color in the unsafe area instead of the image presented below. Is this possible? I can’t move to a table view inside of a view controller, which I would then constrain to the safe area, because my cells are static.

推荐答案

你需要使用 Container View,所以在你的 storyboard 添加一个 View Controller 并放置一个Container View - 通过添加容器视图,它将自动创建一个 segue 和一个视图控制器删除两者.

You need to use a Container View, so add a View Controller in your storyboard and put a Container View in it-by adding the container view it will automatically create a segue and a view controller delete both.

现在从您的 Container View 创建一个到 Table View Controller 的 segue 并选择 Embed.

Now from your Container View create a segue to the Table View Controller and choose Embed.

最后一步是为您的 Container View 设置约束,对您的问题最重要的是最上面的,将其设置为 0 到安全区域.

Last step is to set the constraints for your Container View, the most important for your issue is the top one, set it 0 to the safe area.

这篇关于如何在 Swift/iOS 中将静态表视图控制器单元格约束到安全区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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