我怎样才能避免覆盖 iPhone 上的安全区域,但至少改变它们的颜色?

How can I avoid covering the safe area on iPhones, but at least change their color?

我注意到有些 iPhone 应用程序不仅不能远离 iPhone 上的安全区域,而且还会更改安全区域的背景颜色,同时不会覆盖 iPhone上方状态栏信息、图标、时间等

我可以让我的背景完全覆盖整个屏幕,但 iOS' 顶部信息会消失。

我无法仅使用 Xcode 来找到如何做到这一点 。我通过代码构建所有内容,不使用故事板。

作为奖励,我也很想知道我是否可以更改视图或游戏场景坐标,使 0,0(左下)位于安全区域上方?

这是我通过 Google 找到的代码,它位于顶部但不位于底部。是的,我只是把它扔进了他们我必须再留下来。

我确实注意到,即使我离开了顶部安全区域,iOS 的信息、图标等也没有出现。

view.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
imageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
 imageView.widthAnchor.constraint(equalToConstant: 200).isActive = true
 imageView.heightAnchor.constraint(equalToConstant: 200).isActive = true
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
imageView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50).isActive = true

这是您需要尝试的方法

    mview.translatesAutoresizingMaskIntoConstraints = false
    mview.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor).isActive = true
    mview.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor).isActive = true
    mview.bottomAnchor.constraint(equalToSystemSpacingBelow:view.safeAreaLayoutGuide.bottomAnchor, multiplier: 1.0).isActive = true
    mview.heightAnchor.constraint(equalToConstant: 300).isActive = true

注意:我不知道为什么你的两个实例名称相同......“view