Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.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 Swift约束和;锚定_Ios_Swift_Constraints - Fatal编程技术网

Ios Swift约束和;锚定

Ios Swift约束和;锚定,ios,swift,constraints,Ios,Swift,Constraints,事实上,我正在寻找一个下拉按钮的例子。但不幸的是,它并没有完全起作用,我也不知道动态约束和锚点是如何工作的。因此我请求你的帮助 “NSGenericeException”,原因:“无法使用激活约束 锚和 因为他们没有 共同祖先。约束或其锚定是否引用中的项 不同的视图层次结构?那是违法的 您可以在Github上找到我的源代码: 我发现了类似的问题,他们的解决方案是: 在激活约束之前,检查是否已将以编程方式创建的视图添加到其父视图 检查是否在viewDidLoad()/ViewWillDispla

事实上,我正在寻找一个下拉按钮的例子。但不幸的是,它并没有完全起作用,我也不知道动态约束和锚点是如何工作的。因此我请求你的帮助

“NSGenericeException”,原因:“无法使用激活约束
锚和 因为他们没有 共同祖先。约束或其锚定是否引用中的项 不同的视图层次结构?那是违法的

您可以在Github上找到我的源代码:

我发现了类似的问题,他们的解决方案是:

  • 在激活约束之前,检查是否已将以编程方式创建的视图添加到其父视图

  • 检查是否在viewDidLoad()/ViewWillDisplay()中写入约束激活代码。您应该在updateViewConstraints或ViewWillLayoutSubView中写入约束

  • 检查是否关闭TranslatesAutoResizengMaskintoConstraints


但这对我没有帮助。

对于下拉列表,我更喜欢代码数量少、易于处理的下拉列表

初始化

let dropDown = DropDown()

// The view to which the drop down will appear on
dropDown.anchorView = view // UIView or UIBarButtonItem

// The list of items to display. Can be changed dynamically
dropDown.dataSource = ["Car", "Motorcycle", "Truck"]
dropDown.show()
dropDown.hide()
句柄选择

// Action triggered on selection
dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
  print("Selected item: \(item) at index: \(index)")
}
处理显示和隐藏

let dropDown = DropDown()

// The view to which the drop down will appear on
dropDown.anchorView = view // UIView or UIBarButtonItem

// The list of items to display. Can be changed dynamically
dropDown.dataSource = ["Car", "Motorcycle", "Truck"]
dropDown.show()
dropDown.hide()
非常容易定制


希望这将帮助您

您需要显示下拉菜单,对吗?@GaneshManickam是的,忘记写入,它显示并工作,问题发生在控制器关闭时(当按钮由RemoveFromSuperview方法调用时)