ScrollView中的视图未正确更新

时间:2019-08-02 11:12:58

标签: ios swift cocoa-touch uiscrollview constraints

我有一个带有两个视图的ScrollView,当我单击“视图1”上的更多按钮时--->我要删除该按钮并从.xib中加载大视图。这里的问题是底部视图“视图2”没有移到底部,并且ScrollView没有滚动。

enter image description here

我的代码是:

@IBAction func onClickMoreBtn(_ sender: UIButton) {
    DispatchQueue.main.async {
        self.moreBtn.removeFromSuperview()

        //Load view
        let loadMoreView = Bundle.main.loadNibNamed("SubView", owner: nil, options: nil)?.first as? SubView
        self.view1.addSubview(loadMoreView!)
        self.view1.frame = CGRect(x: self.view1.frame.origin.x, y: self.view1.frame.origin.y, width: self.view1.frame.width, height: 400)
        //Set the frame of the more view to match its superview (the view1)
        loadMoreView?.frame = self.view1.bounds
        // let it resize if needed (such as device rotation)
        loadMoreView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        print(loadMoreView?.frame as Any)


    }

}

0 个答案:

没有答案