Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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 UISegmentedControl不起作用的程序约束_Ios_Uikit_Constraints - Fatal编程技术网

Ios UISegmentedControl不起作用的程序约束

Ios UISegmentedControl不起作用的程序约束,ios,uikit,constraints,Ios,Uikit,Constraints,我试图使用UIKit编程约束创建一个简单的界面,其中有一行,左侧有一个UISegmentedControl,右侧有一个黄色UIView 问题是,我希望UIView延伸到视图的整个高度,但是由于某些原因,它的底部锚点不在段控制器的实际底部 这是密码 parentGuide = top.layoutMarginsGuide let choices = UISegmentedControl(items: ["Op1", "Op2"]) choices.translatesAutoresizingM

我试图使用UIKit编程约束创建一个简单的界面,其中有一行,左侧有一个UISegmentedControl,右侧有一个黄色UIView

问题是,我希望UIView延伸到视图的整个高度,但是由于某些原因,它的底部锚点不在段控制器的实际底部

这是密码

parentGuide = top.layoutMarginsGuide

let choices = UISegmentedControl(items: ["Op1", "Op2"])
choices.translatesAutoresizingMaskIntoConstraints = false
top.addSubview(choices)
choices.leadingAnchor.constraint(equalTo: parentGuide.leadingAnchor).isActive = true
choices.topAnchor.constraint(equalTo: parentGuide.topAnchor).isActive = true

let yellow = UIView()
yellow.translatesAutoresizingMaskIntoConstraints = false
top.addSubview(yellow)
yellow.backgroundColor = UIColor.yellow
yellow.trailingAnchor.constraint(equalTo: parentGuide.trailingAnchor).isActive = true
yellow.topAnchor.constraint(equalTo: parentGuide.topAnchor).isActive = true
yellow.leadingAnchor.constraint(equalTo: parentGuide.trailingAnchor, constant: -40).isActive = true
yellow.bottomAnchor.constraint(equalTo: choices.layoutMarginsGuide.bottomAnchor).isActive = true
为什么会发生这种情况?我如何修复它?

而不是

yellow.bottomAnchor.constraint(equalTo: choices.layoutMarginsGuide.bottomAnchor).isActive = true
成功

yellow.bottomAnchor.constraint(equalTo: choices.bottomAnchor).isActive = true