ios - Collection View 图像卡在两者之间

标签 ios swift3 uiscrollview uicollectionviewcell collectionview

enter image description here

我在 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/

相关文章:

ios - 更改添加为 subview 的搜索栏的宽度

ios - 获取字符串中最后一个字符类型之后的文本

swift - thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0) 是什么意思

带有约束的 ScrollView 内的 iOS Swift stackview

objective-c - UIScrollView 内的绘图 View

ios - 如何在 iOS 中从 PHPhotoLibrary 获取 ref url?

objective-c - 如何使用图像创建自定义的分组 UITableView

ios - 尝试 Seque 到导航 View Controller 时出错无法将类型 'UIViewController' 的值转换为强制类型 'UINavigationController'

ios - Branch.io getShortUrl通用分支对象

ios - UIScrollView 的 UIPagerView 滚动问题