ios - 屏幕旋转时 ViewController 中的白线

标签 ios swift uiviewcontroller

我是 iOS 开发新手。我遇到了这个问题,当我在 iPhone X 模拟器上旋转屏幕时,我在屏幕的侧面出现了白色条纹,如您在第二张图片上看到的那样。 enter image description here

enter image description here

我已经为 ViewController 和 TableView 设置了背景。

 override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = Colors.backGround
    view.tintColor = Colors.backGround

它没有帮助。当应用程序从横向模式启动时,问题就会消失。

最佳答案

您的蓝色 View 区域有 leadingtrailingsafe area 的约束。 只需进入 superview

Trailing and leading constraint

编辑: 这是使用 swift 代码实现的相同代码

//Creating tableview
let tableView = UITableView()
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.backgroundColor = .lightGray
tableView.dataSource = self
self.view.addSubview(tableView)

//Setting layout of tableview
tableView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
tableView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
tableView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true

//Setting insets for respect safe area
tableView.contentInset = self.view.safeAreaInsets


下面是截图。

垂直

Add UITableView with programming coding vertical

横向

Add UITableView with programming coding horizontal

关于ios - 屏幕旋转时 ViewController 中的白线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57789348/

相关文章:

ios - Gigya电话注册

ios - 如何获取 Collection View 来控制表格 View 中的搜索结果?

ios - 如何使用 Swift 4 将 JSON 值附加到数组中?

ios - 如何从 GameScene 刷新 GameViewController?

ios - 无法设置 UIViewController ios 的属性

ios - AFNetworking 2.0 + TLS 1.2

ios - 如何检查 ios 中的互联网连接?

arrays - 使用另一个数组调用字典键

ios - 从 mapview 获取所有 GMSMarker 并在不使用 mapview.clear() 的情况下删除所有标记

ios - 单击 Swift XCode 中的编程按钮后如何在 Controller 之间切换