[英]How to add UIViewController into UIScrollView in swift?
I want to add UIViewController into UIScrollView. 我想将UIViewController添加到UIScrollView中。
I searching and tried, but I can't find solution. 我搜索并尝试过,但是找不到解决方案。
The most understandable way is this. 最可理解的方式是这样。
Here is my code. 这是我的代码。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
self.scrollView.contentSize.width = self.view.frame.width * 2
let test = self.storyboard?.instantiateViewController(withIdentifier: "Test") as! TestViewController
self.addChild(test)
self.scrollView.addSubview(test.view)
test.willMove(toParent: self)
test.view.frame.origin = CGPoint.zero
}
}
But, I this way is error like this. 但是,我这种方式是这样的错误。
How to add UIViewController into UIScrollView?? 如何将UIViewController添加到UIScrollView中?
Please Help me. 请帮我。
在情节scrollView
,只需拖放一个containerView
, scrollView
根据需要在您的scrollView
创建一个UIViewController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.