Swift Xib子视图未填充视图

时间:2019-01-18 10:32:09

标签: swift

我正在尝试将子视图(从xib)呈现到视图中。子视图显示在视图中,但未按预期填充视图。子视图为什么不占据imageControllerPlaceHolder的框架?

 var imageScrollerSubView: UIView?

     override func viewDidLoad() {
            super.viewDidLoad()

            imageScrollerSubView = UINib(nibName: "ImageScroller", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as? UIView
            imageScrollerSubView?.frame.size.height = ImageScrollerPlaceHolder.frame.size.height
            imageScrollerSubView?.frame.size.width = ImageScrollerPlaceHolder.frame.size.width
            ImageScrollerPlaceHolder.addSubview(imageScrollerSubView!)


        }

1 个答案:

答案 0 :(得分:0)

尝试用viewDidLayoutSubviews方法更新目标视框

override func viewDidLayoutSubviews() {
        imageScrollerSubView?.frame.size.height = ImageScrollerPlaceHolder.frame.size.height
        imageScrollerSubView?.frame.size.width = ImageScrollerPlaceHolder.frame.size.width
}