将 UICollectionViewCell 大小动画化到 CollectionView 边界之外 - Swift

Animating a CollectionViewCell Size To Outside CollectionView Boundary - Swift

我一直致力于为一些 collectionViewCells 的大小设置动画。它在我的 collectionViewController 中运行良好,但在另一个 UIViewController 中我有一个小的 collectionView 和其他对象,单元格只会增长到 collectionView 的大小。我希望它能填满整个屏幕。这样做的最佳方法是什么?

这是我当前的代码:

    var largePhotoIndexPath : NSIndexPath? {
    didSet{

        var indexPaths = [NSIndexPath]()
        if largePhotoIndexPath != nil {
            indexPaths.append(largePhotoIndexPath!)
        }
        if oldValue != nil {
            indexPaths.append(oldValue!)
        }
        collectionView?.performBatchUpdates({ () -> Void in
            self.collectionView?.reloadItemsAtIndexPaths(indexPaths)
            return
            }){
                completed in

                if self.largePhotoIndexPath != nil {
                    self.collectionView?.scrollToItemAtIndexPath(self.largePhotoIndexPath!, atScrollPosition: .CenteredVertically, animated: true)
                }
        }
    }
}

func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {
    if largePhotoIndexPath == indexPath {
        largePhotoIndexPath = nil
    }
    else {
        largePhotoIndexPath = indexPath
    }
    return false
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

    let dealImage: UIImage = UIImage(data: self.imageDataArray[indexPath.row])!
    let dealPhoto: UIImageView = UIImageView(image: dealImage)

    if indexPath == largePhotoIndexPath {

        var size = UIScreen.mainScreen().bounds
        dealPhoto.frame == size
        return CGSize(width: 300, height: 525)

    }
    return CGSize(width: 100, height: 175)
}



func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return self.imageDataArray.count

}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! TrailInfoCollectionViewCell

    cell.imageView.image = UIImage(data: self.imageDataArray[indexPath.row])

    return cell
}

以及我 select 单元格前后的一些图像:

如您所见,图像已经增长到我想要的大小,但受到 collectionView 的限制。 collectionViewCell 是否有可能超出 collectionView 的边界,还是我必须以其他方式进行?我只想设置一个隐藏的 imageView,但我喜欢动画过渡。

感谢您的帮助。如果您需要更多详细信息,请告诉我。

clipsToBounds 属性是防止子视图超过其父视图的原因。将其设置为 false,它应该可以工作。