我试图在容器视图中设置视图。必须以这种方式完成,因为swipeView
内的视图有几个不同的控制器。
@IBOutlet weak var containerView: ContainerView!
override func viewDidLoad() {
super.viewDidLoad()
//Some other stuff
//Create new swipeView
var swipeView = MDCSwipeToChooseView(frame: containerView.frame, options: options)
//Add the view from the controller to the swipeView
swipeView.addSubview(containerViewController.view)
//Add the swipeView to the main view
self.view.addSubview(swipeView)
我最终得到了这个
白色区域是应继承containerView
大小的视图。 containerView
是背景中的粉红色,并且显示正确。我注意到containerView.frame
从故事板返回组件的大小,参见图2.通过调用containerView.frame
获得的帧是调整视图大小以满足所有约束之前的帧。我如何获得正确的值?
答案 0 :(得分:1)
在viewDidLayoutSubviews()
而不是viewDidLoad()
中放置相同的代码解决了这个问题。