我在 collectionView Cell 中实现了一个 collectionView。 让我们命名外部 collectionView = collectionView(1) 和 collectionView inside cell = collectionView(2) collectionView(2)中有滚动图片。
collectionView(1) 将垂直滚动,collectionView(2) 将水平滚动。
collectionView(2) 函数出现在 collectionView(1) Cell 文件中。
我的问题是,当我滚动 collectionView(1) 时,图像卡在 collectionView(2) 之间
以下代码在 CollectionViewCell 文件中。
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.imagesCount
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomePostImagesCollectionViewCell", for: indexPath)as! HomePostImagesCollectionViewCell
cell.image.image = UIImage(named: "\((indexPath as NSIndexPath).item % imagesCount)")
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
DispatchQueue.main.async {
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = mainStoryboard.instantiateViewController(withIdentifier: "OpenPostViewController")as! OpenPostViewController
let navigationController = UIApplication.shared.keyWindow?.rootViewController as! UINavigationController
navigationController.pushViewController(vc, animated: true)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
最佳答案
嘿,我也遇到了这个问题,我用过
//Updation of screen
func layoutChange() {
self.view.layoutIfNeeded()
self.view.setNeedsUpdateConstraints()
self.scrollView.layoutIfNeeded()
self.scrollView.setNeedsUpdateConstraints()
}
或者您可以引用此链接 setNeedsLayout vs. setNeedsUpdateConstraints and layoutIfNeeded vs updateConstraintsIfNeeded
关于ios - Collection View 图像卡在两者之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46668595/