【发布时间】:2017-08-18 00:31:30
【问题描述】:
在 IB 内部,我有一个带有 segmentedControl 和 2 个 containerViews 的 viewController。在每个 containerView 中我都有一个 tableView。从每个 tableView 我推送一个 detailView。我的自动布局在 IB 中。
一旦我选择了一个段,我就会看到相应的 tableView,我选择一个单元格,正确的 detailView 就会被推送到场景中。
问题是一旦将 detailView 推送到 segmentedControl 上仍然可见。我决定隐藏有效的分段控制,但那里有一个很大的空白空间。我试图以编程方式增加 detailView 视图的大小,但它没有扩大。从我读到的内容来看,这是因为我在情节提要中设置了初始约束。
如何以编程方式扩展 detailView 的视图?
代码:
DetailViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
//this isn't increasing the view's size
self.view.frame.size.height += 20.0
//doesn't work. I get an error on the last argument
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height += 20.0)
//doesn't work. I get an error on the last argument
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.size.height += 20.0)
}
}
错误:
//Error for the last argument- height: *self.view.frame.height += 20.0*
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height += 20.0)
变异运算符的左侧不可变:'height' 是 get-only 属性
//Error for the last argument- *self.view.frame.size.height += 20.0*:
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.size.height += 20.0)
无法使用参数列表为“CGRect”类型调用初始化程序 type '(x: Int, y: Int, width: CGFloat, height: ())'
【问题讨论】:
标签: ios swift xcode uiview constraints