ios - Swift 2 - 将选定的 CollectionView 单元格放在其他单元格前面

标签 ios uicollectionview swift2

我的 View Controller 中有一个 UICollectionView。它已经设置好并且工作正常。

我试图在按下单元格本身内的按钮时缩放单元格。

我的代码缩放了单元格但是,我找不到强制选择的单元格转到其他单元格前面的方法。 现在选择的单元格总是在选择之前的单元格之后。

如何强制选中的单元格在其他单元格之前缩放?

@IBAction func detailBtnAction(sender:UIButton){

        let indexUser = (sender.layer.valueForKey("indexBtn")) as! Int
        let indexPath = NSIndexPath(forItem: indexUser, inSection: 0)
        let feedCell = feedCollectionView.cellForItemAtIndexPath(indexPath)
            feedCell?.bringSubviewToFront(feedCollectionView)

        feedCell?.contentView.bringSubviewToFront(feedCollectionView)

        UIView.animateWithDuration(1.0) { () -> Void in
            feedCell?.transform = CGAffineTransformMakeScale(5, 5)
        }

}

最佳答案

看来你把事情的顺序搞混了。

来自文档:

Moves the specified subview so that it appears on top of its siblings.

func bringSubviewToFront(_ view: UIView)

Parameters

view - The subview to move to the front.

This method moves the specified view to the end of the array of views in the subviews property.

所以你的电话:
feedCell?.contentView.bringSubviewToFront(feedCollectionView)
实际上意味着单元格内容 View 应该将 feedCollectionView 移到前面。
现在,这是一些基于命名的有根据的猜测,但它应该看起来像这样:
feedCollectionView.bringSubviewToFront(feedCell?)

您可以将单元格本身传递到那里,因为它继承自 UIView

关于ios - Swift 2 - 将选定的 CollectionView 单元格放在其他单元格前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34067009/

相关文章:

ios - 单击在数组中添加/删除时,Swift Collection View didSelectItemAtIndexPath

uinavigationcontroller - UISplitViewController 中开始/结束外观转换的不平衡调用

nested - 如何在Swift 2.0中处理连续多次尝试

ios - 用相机拍照旋转asset.fullScreenImage 90度?

ios - iOS 应用程序在后台可以做什么?

ios - 无法将消息从 inappbrowser 发布到 Cordova 应用程序

swift - collectionview 上的非粘性标题部分单元格(补充 View )

ios - 如何将静态元素添加到 UICollectionViewController 或使它们与其共享同一屏幕

ios - 尝试在 Swift 2.0 中解析 json 数据时出现错误?

ios - 当我尝试在代码块外编辑文本标签时,swift animateWithDuration 中断