收藏视图图像夹在中间

时间:2017-10-10 13:53:57

标签: ios swift3 uiscrollview uicollectionviewcell collectionview

enter image description here

我在collectionView Cell中实现了一个collectionView。 让我们看一下名字外的collectionView = collectionView(1)和collectionView里面的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
}

1 个答案:

答案 0 :(得分: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