OGeek|极客世界-中国程序员成长平台

标题: ios - Swift 2 - 将选定的 CollectionView 单元格放在其他单元格的前面 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:14
标题: ios - Swift 2 - 将选定的 CollectionView 单元格放在其他单元格的前面

我的 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)
        }

}



Best Answer-推荐答案


看来你的顺序有点困惑。

来自文档:

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4