我是 iOS 开发新手。我遇到了这个问题,当我在 iPhone X 模拟器上旋转屏幕时,我在屏幕的侧面出现了白色条纹,如您在第二张图片上看到的那样。
我已经为 ViewController 和 TableView 设置了背景。
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Colors.backGround
view.tintColor = Colors.backGround
它没有帮助。当应用程序从横向模式启动时,问题就会消失。
最佳答案
您的蓝色 View 区域有 leading
和 trailing
到 safe area
的约束。
只需进入 superview
。
编辑: 这是使用 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
关于ios - 屏幕旋转时 ViewController 中的白线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57789348/