我们最近决定尝试将 Parchment 合并到我们的应用程序中,因为它可以完美地满足我们的需求。我们还添加了一个折叠标题效果。所以我们首先做了一个测试项目来测试它,就像我们将它重构到我们自己的应用程序中一样,我们注意到一个非常奇怪的错误,我们似乎无法查明问题所在。起初我们认为它可能在我们自己的应用程序中,但我打开了测试项目,它也在那里。
此 GIF 将向您展示问题。当我们只有一个标签/屏幕时,情况会更糟。然后,在不触发此问题的情况下,甚至很难向下滚动以正确刷新。
任何人都知道这可能发生的原因和地点?
Parchment 实现的示例代码:
private var pagingViewController = PagingViewController()
pagingViewController.dataSource = self
pagingViewController.register(PagingCustomCell.self, for: CustomPagingItem.self)
addChild(pagingViewController)
pagingViewController.borderOptions = .hidden
pagingViewController.menuItemSize = .selfSizing(estimatedWidth: 100, height: 40)
pagingViewController.indicatorClass = CustomIndicatorView.self
pagingViewController.indicatorOptions = .visible(
height: 32,
zIndex: -1,
spacing: .zero,
insets: UIEdgeInsets(top: 0, left: 0, bottom: 5, right: 0)
)
pagingViewController.indicatorColor = .purple
pagingViewController.collectionView.contentInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
view.addSubview(pagingViewController.view)
pagingViewController.backgroundColor = .clear
pagingViewController.didMove(toParent: self)
pagingViewController.view.translatesAutoresizingMaskIntoConstraints = false
pagingViewController.view.snp.makeConstraints { (m) in
m.top.equalTo(headerView.snp.bottom)
m.left.right.bottom.equalToSuperview()
}
// Put shadow beneath tabs for collapsing header
pagingViewController.collectionView.layer.masksToBounds = true
pagingViewController.collectionView.layer.shadowOffset = CGSize(width: 0, height: 1)
pagingViewController.collectionView.layer.shadowRadius = 1
pagingViewController.collectionView.layer.shadowOpacity = 0.3
extension ViewController: PagingViewControllerDataSource {
func numberOfViewControllers(in pagingViewController: PagingViewController) -> Int {
return pages.count
}
func pagingViewController(_: PagingViewController, viewControllerAt index: Int) -> UIViewController {
let currentVc = pages[index]
if let currentVc = currentVc {
return currentVc
} else {
let tableViewVC = TableViewController()
tableViewVC.innerTableViewScrollDelegate = self
pages[index] = tableViewVC
return tableViewVC
}
}
func pagingViewController(_: PagingViewController, pagingItemAt index: Int) -> PagingItem {
return CustomPagingItem(index: index, text: "View \(index+1)")
}
}