gpt4 book ai didi

swift 4 : scrollViewDidScroll not working

转载 作者:行者123 更新时间:2023-11-28 07:57:41 29 4
gpt4 key购买 nike

  1. 我创建了第一个 View Controller “MainViewController”,并将带有导出 contentContainer 的容器 View 放入其中。
  2. 我创建了第二个 View Controller “AboutContentViewController”并将其放入 ScrollView
  3. 我以编程方式连接 Container View 和 AboutContentViewController:

class MainViewController: UIViewController {
@IBOutlet weak var contentContainer: UIView!

override func viewDidLoad() {
let contentControllerName = "AboutContentViewController"
if let contentController = storyboard?.instantiateViewController(withIdentifier: contentControllerName) {
contentContainer.addSubview(contentController.view)
}
}
}

  1. 我尝试使用此代码捕获 scrollViewDidScroll 事件

class AboutContentViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var topGalleryScrollView: UIScrollView!

override func viewDidLoad() {
super.viewDidLoad()

topGalleryScrollView.contentSize = CGSize(width: 3750.0, height: 417.0)
topGalleryScrollView.delegate = self
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("scrollViewDidScroll called")
}
}

在此上下文中,scrollViewDidScroll 事件不起作用

最佳答案

我已经解决了问题。在将其 View 添加到容器之前,需要将 AboutContentViewController 作为 subview Controller 添加到 MainVewController:

class MainViewController: UIViewController {
@IBOutlet weak var contentContainer: UIView!

override func viewDidLoad() {
let contentControllerName = "AboutContentViewController"
if let contentController = storyboard?.instantiateViewController(withIdentifier: contentControllerName) {
addChildViewController(contentController)
contentContainer.addSubview(contentController.view)
}
}
}

关于 swift 4 : scrollViewDidScroll not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47568988/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com