UICollectionView isUserInteractionEnabled阻止单元格交互

时间:2017-10-10 12:25:18

标签: ios swift uicollectionview uicollectionviewcell uianimation

我有一个UICollectionView,它有正常的细胞。

每个单元格内都有一个UICollectionViewController

当我点击一个单元格时,我将其展开以适合窗口屏幕,但我在这里遇到了一些问题:

如果我在展开的单元格中滚动,整个屏幕会滚动;

我正在尝试阻止superview集合视图点击和滚动。

为了做到这一点,在展开所选单元格以适合所需的框架后,我设置了collectionView.isScrollEnabled = falsecollectionView.isUserInteractionEnabled = false,但是由此我遇到了另一个问题:扩展的单元格没有与任何触摸互动。

我怎样才能做到这一点?展开单元格并阻止滚动视图滚动,阻止滚动视图交互,但是启用单元格交互(滚动点击等)?

以下是一些代码:

主Feed控制器

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    guard let cell = collectionView.cellForItem(at: indexPath) as? FeedCell else { return }
    let theAttributes:UICollectionViewLayoutAttributes! = collectionView.layoutAttributesForItem(at: indexPath)
    let cellFrameInSuperview:CGRect = collectionView.convert(theAttributes.frame, to: collectionView)

    cell.superview?.bringSubview(toFront: cell)
    cell.backupFrame = cellFrameInSuperview

    let newFrame = CGRect(x: 0, y: collectionView.contentOffset.y, width: view.frame.width, height: view.frame.height)
    UIView.animate(withDuration: 0.2, animations: {
        cell.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
    }) { (_) in
        UIView.animate(withDuration: 0.1, animations: {
            cell.transform = CGAffineTransform(scaleX: 1, y: 1)
        }, completion: { (_) in
            UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.7, options: .curveEaseInOut, animations: {
                cell.frame = newFrame                   
            },completion: {(_) in
                cell.presentDismissButton()
                self.collectionView.isScrollEnabled = false
                self.collectionView.isUserInteractionEnabled = false
            })
        })                      
    }
}

扩展单元格关闭按钮属性

@objc func dismiss() {
    UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1, options: .allowAnimatedContent, animations: {
        self.frame = self.backupFrame!
        self.sendSubview(toBack: self)
        self.dismissButton.alpha = 0
    },completion: nil) 
}

在dismiss属性中,我可以将superview交互设置为再次启用,但是对于展开的框架,我无法与其交互。

如果我没有禁用Main feed collectionView交互,我在这里遇到的一个问题是,当我点击扩展单元格的任何地方时,它将展开另一个单元格(位于我的扩展单元格后面,它将从{}接收触摸事件{1}}

任何提示? 谢谢。

1 个答案:

答案 0 :(得分:0)

如果设置userInteractionEnabled = false,则无法与任何子视图进行互动。仅仅禁用滚动是不够的?

e.g。尝试删除self.collectionView.isUserInteractionEnabled = false 从你的完成块?

相关问题