Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 子视图容器don';与swift中所需的宽度不匹配_Ios_Swift_Uicontainerview_Childviews - Fatal编程技术网

Ios 子视图容器don';与swift中所需的宽度不匹配

Ios 子视图容器don';与swift中所需的宽度不匹配,ios,swift,uicontainerview,childviews,Ios,Swift,Uicontainerview,Childviews,我有一个视图容器,只显示一个带有电话的屏幕和两个带有标签的屏幕。因此,在ViewDidLoad()中,我使用了一个 func addListController(){ self.addChildViewController(listController!) listController?.view.frame = defineListSize() self.containerView.addSubview((listController?.view)!) lis

我有一个视图容器,只显示一个带有电话的屏幕和两个带有标签的屏幕。因此,在ViewDidLoad()中,我使用了一个

 func addListController(){
    self.addChildViewController(listController!)
    listController?.view.frame = defineListSize()
    self.containerView.addSubview((listController?.view)!)
    listController?.didMove(toParentViewController: self)
}
其中方法defineListSize确定第一个子项的大小

 func defineListSize() -> CGRect {
    var rect :CGRect = CGRect(x: 0, y: 0, width: self.containerView.frame.size.width, height: self.containerView.frame.size.height)

    switch (deviceIdiom) {
    case .tv:
        rect = CGRect(x: 0, y: 0, width: self.containerView.frame.size.width/2, height: self.containerView.frame.size.height)
    case .pad:
        rect = CGRect(x: 0, y: 0, width: self.containerView.frame.size.width/2, height: self.containerView.frame.size.height)
    case .phone:
        rect = CGRect(x: 0, y: 0, width: self.containerView.frame.size.width, height: self.containerView.frame.size.height)
    case .unspecified: break
    default: break
    }

    return rect
}
但是,当在tablet上添加第一个子项时,它始终比容器视图的一半宽。尽管在调试中,我可以看到rect具有良好的数据。我尝试在ViewWillAppeard或viewWillLayoutSubviews()中使用addListController(),但结果相同。 添加到右侧的第二个子视图具有良好的尺寸,并剪切第一个子视图的右侧部分

那么问题出在哪里呢?
谢谢

如果有更改,请尝试在viewDidLayoutSubviews中调用它,如消息最后一段所述,已完成,但没有更改。您说您尝试过的更改将导致布局未完成布局,但可能是您遇到了非常相同的问题。对不起,我读得不好。我刚试过,效果不错。多谢各位