Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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
在UIContainerView swift ios中调整子视图控制器的大小_Ios_Swift_Autolayout - Fatal编程技术网

在UIContainerView swift ios中调整子视图控制器的大小

在UIContainerView swift ios中调整子视图控制器的大小,ios,swift,autolayout,Ios,Swift,Autolayout,我正在创建一个应用程序,其中我必须在视图控制器内打开2-3个视图控制器,因为我想为这些视图控制器共享相同的滑动抽屉和导航栏。我遵循了教程 我在MainController内部使用了ContainerView,并且正确添加了子控制器,但是我很难调整子控制器的大小以匹配ContainerView self.mainContainer.addSubview(vc.view) self.mainContainer.translatesAutoresizingMaskIntoConstraints =

我正在创建一个应用程序,其中我必须在视图控制器内打开2-3个视图控制器,因为我想为这些视图控制器共享相同的滑动抽屉和导航栏。我遵循了教程

我在MainController内部使用了ContainerView,并且正确添加了子控制器,但是我很难调整子控制器的大小以匹配ContainerView

 self.mainContainer.addSubview(vc.view)
 self.mainContainer.translatesAutoresizingMaskIntoConstraints = false
 addChildViewController(vc)
 NSLayoutConstraint.activate([
 vc.view.leadingAnchor.constraint(equalTo:mainContainer.leadingAnchor),
 vc.view.trailingAnchor.constraint(equalTo: mainContainer.trailingAnchor),
 vc.view.topAnchor.constraint(equalTo: mainContainer.topAnchor),
 vc.view.bottomAnchor.constraint(equalTo: mainContainer.bottomAnchor)
 ])
vc.didMove(toParentViewController: self)
我得到了以下错误

[LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x170095c70 h=-&- v=-&- UIView:0x127e17630.midY == UIView:0x127e15070.midY + 32   (active)>",
    "<NSLayoutConstraint:0x1740970c0 V:|-(0)-[UIView:0x127e17630]   (active, names: '|':UIView:0x127e15070 )>",
    "<NSLayoutConstraint:0x174097020 UIView:0x127e17630.bottom == UIView:0x127e15070.bottom   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x174097020 UIView:0x127e17630.bottom == UIView:0x127e15070.bottom   (active)>
[LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
""
)
将尝试通过打破约束进行恢复
我认为self.mainContainer.translatesAutoresizingMaskIntoConstraints=false的 子视图控制器未正确调整大小,因为在主控制器中,导航栏约为64,并且在子视图控制器中从底部剪裁相同高度的部分

MainController的元素约束

  • 导航栏左=上=右=0,高度=64

  • UIContainerView左=右=底部=0,顶部到导航栏=0


  • vc.view.translatesAutoResizengMaskintoConstraints=false

    您可以简单地设置
    vc
    的框架,即

        vc.view.frame = self.containerView.bounds //Here
        self.containerView.addSubview(vc.view)
        self.addChildViewController(vc)
        vc.didMove(toParentViewController: self)
    

    主容器限制?对不起,我是说它的主控制器。我放在主控制器中的元素我是否应该发布一个演示代码,以供通过编程方式添加约束时参考?你可以检查一下,伙计,我可能做错了什么事,我能得到你的代码文件吗?还是Xcode项目?