我已经在collectionView单元内部实现了collectionView。
让我们命名外部collectionView = collectionView(1),并在单元格内部命名collectionView = collectionView(2)
collectionView(2)中有滚动图像。
collectionView(1)将垂直滚动,collectionView(2)将水平滚动。
collectionView(1)单元文件中提供了collectionView(2)函数。
我的问题是,当我滚动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 - 收藏夹图像夹在中间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46668595/