动态自动布局
Dynamic auto-layout
我是编程新手,我知道在 internet/Whosebug 中有很多关于自动布局或带约束的操作的工作人员,我到处搜索,但无法找到我的答案问题,所以请告知是否可以。
例如这里是
UI example
所以我有一个 tableView,它是 ViewController 顶部的顶部约束,而 textView 是 tableView 底部的顶部约束。所以问题是,如何根据 TableView 中数组的大小动态更改约束。如果 TableView 为空,则将 textView 赋值给 ViewController,如果 tableView 的数组 > 0,则赋值给 TableView 的底部。我试过这样的东西
@IBOutlet weak var textViewTopConstraints: NSLayoutConstraint! {
didSet {
if array.isEmpty {
textViewTopConstraints.isActive = false
textView.topAnchor.constraint(equalTo: ViewController.top, constant: 8).isActive = true
} else if imageURL.count > 0 {
textViewTopConstraints.isActive = false
textView.topAnchor.constraint(equalTo: tableView.bottomAnchor, constant: 8).isActive = true
}
}
}
然而,它仅在加载应用程序时有效,如果数组发生更改则不会调用。所以基本上,我无法理解如何调用函数或根据我的数组大小跟踪和更改我的约束的东西。如果这是重复的,能否请您引导我到右边 link 那里我可以查看此信息。
更改 table 视图框架并连接文本字段和 table 视图之间的约束。 Link 设置 table 视图框架为:- Change UITableView height dynamically
我是编程新手,我知道在 internet/Whosebug 中有很多关于自动布局或带约束的操作的工作人员,我到处搜索,但无法找到我的答案问题,所以请告知是否可以。 例如这里是 UI example
所以我有一个 tableView,它是 ViewController 顶部的顶部约束,而 textView 是 tableView 底部的顶部约束。所以问题是,如何根据 TableView 中数组的大小动态更改约束。如果 TableView 为空,则将 textView 赋值给 ViewController,如果 tableView 的数组 > 0,则赋值给 TableView 的底部。我试过这样的东西
@IBOutlet weak var textViewTopConstraints: NSLayoutConstraint! {
didSet {
if array.isEmpty {
textViewTopConstraints.isActive = false
textView.topAnchor.constraint(equalTo: ViewController.top, constant: 8).isActive = true
} else if imageURL.count > 0 {
textViewTopConstraints.isActive = false
textView.topAnchor.constraint(equalTo: tableView.bottomAnchor, constant: 8).isActive = true
}
}
}
然而,它仅在加载应用程序时有效,如果数组发生更改则不会调用。所以基本上,我无法理解如何调用函数或根据我的数组大小跟踪和更改我的约束的东西。如果这是重复的,能否请您引导我到右边 link 那里我可以查看此信息。
更改 table 视图框架并连接文本字段和 table 视图之间的约束。 Link 设置 table 视图框架为:- Change UITableView height dynamically