【发布时间】:2018-03-09 06:51:54
【问题描述】:
我在尝试正确调整 UIView 大小时遇到问题。
下面的示例场景:
// other view controller initializations
let containerView = UIView(frame: CGRect(x:0, y:0, width: self.view.bounds.width, height: self.view.bounds.height))
self.view.addSubview(containerView)
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let subView = UIView(frame: CGRect(x:0, y:0, width:containerView.bounds.size.width / 2, height: containerView.bounds.size.height))
containerView.addSubview(subView)
subView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
假设我想将 containerView 调整为特定的高度和宽度,这样子视图也会与 containerView 并行调整自身的大小。
我怎样才能做到这一点?
【问题讨论】:
-
你可以设置
subViews的高度和宽度锚点,而不是在构造函数中指定它 -
你的错误是什么?上面的代码工作完美。尝试分配两个视图的 backgroundColor 进行测试
-
最好的办法是自动布局...
-
你们能举一个例子 sn-p 或这个场景吗?
标签: ios swift uiview resize calayer