ios - subview Controller View 不适合 parent 在 iPhone X 上的 View

标签 ios swift uiviewcontroller uinavigationcontroller

我正在使用 subview Controller 在我的场景中呈现各种状态。我有:每个状态的 LoadingViewController、FailureViewController 和 TableViewController。

extension UIViewController {
    func add(_ child: UIViewController) {
        addChild(child)
        view.addSubview(child.view)
        child.didMove(toParent: self)
    }

    func remove() {
        guard parent != nil else {
            return
        }
        willMove(toParent: nil)
        removeFromParent()
        view.removeFromSuperview()
    }
}

我的问题是,子 Controller View 在 iPhone X 上不完全适合父 View (其他设备也很好)。谢谢

enter image description here

最佳答案

为什么不尝试向 subview 添加显式框架,即

func add(_ child: UIViewController) {
    addChild(child)
    child.view.frame = (your expected frame)
    view.addSubview(child.view)
    child.didMove(toParent: self)
}

关于ios - subview Controller View 不适合 parent 在 iPhone X 上的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52835010/

相关文章:

ios - 如何删除没有对象和使用 block 定义的观察者?

ios - 无法绘制图像。

ios - Swift 代码错误 : CMVideoFormatDescriptionGetCleanAperture

ios - 返回的对象类型与函数体 swift objc 中的对象类型不同

ios - 复选框保存/加载 NSUserdefaults

ios - UINavigationBar 从大标题跳到小标题,同时推送到带有嵌入式 UITableView iOS 11 的 UIViewController

iphone - 停止模态 UIViewController 旋转

ios - Xcode 找不到任何 iOS App Store 配置文件

ios - Objective-c 添加到具有不同属性的相同实例的数组

ios - 旋转图像变得扭曲和模糊?