我正在尝试将子视图(从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!)
}
答案 0 :(得分:0)
尝试用viewDidLayoutSubviews
方法更新目标视框
override func viewDidLayoutSubviews() {
imageScrollerSubView?.frame.size.height = ImageScrollerPlaceHolder.frame.size.height
imageScrollerSubView?.frame.size.width = ImageScrollerPlaceHolder.frame.size.width
}