需求:
我尝试过的:
我试过tableview,滚动视图,但没有运气。最后想尝试一下收藏视图,任何人都可以帮我解决如何继续收集视图。如果我们使用集合视图,将来我们会遇到任何复杂情况。
StackView
的CollectionView
的TableView
注意:您可以同时使用CollectionView
或TableView
但我更喜欢这两种不同,因此我不需要在委托和数据源中放置条件,我可以轻松管理。选择是你喜欢的。
CollectionView
和TableView
中设置数据。@IBAction func btnToggle(_ sender: Any) {
colView.isHidden = !colView.isHidden
}
@IBAction func btnToggle(_ sender: Any) {
UIView.animate(withDuration: 0.3) {
self.colView.isHidden = !self.colView.isHidden
}
}
输出:
编辑
您可以在scrollview中使用stackView并关闭colview,tblView滚动。检查如下:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
colView.isScrollEnabled = false
tblView.isScrollEnabled = false
colView.reloadData()
tblView.reloadData()
scrollView.contentSize = CGSize(width: self.view.frame.width,
height: max(colView.contentSize.height, tblView.contentSize.height))
stackHeight.constant = scrollView.contentSize.height
}
注意:它可能会导致一些意外的输出(可能/不可能),因此您需要处理它。
输出:
您需要的是具有自定义布局的UICollectionView。您可以使用此方法获得所需的效果。
有教程的基调如何实现自己的自定义布局。 Here就是其中之一