Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift中更改tvOS中collectionView单元格的位置_Ios_Swift_Uicollectionview_Uicollectionviewcell_Zposition - Fatal编程技术网

Ios 在Swift中更改tvOS中collectionView单元格的位置

Ios 在Swift中更改tvOS中collectionView单元格的位置,ios,swift,uicollectionview,uicollectionviewcell,zposition,Ios,Swift,Uicollectionview,Uicollectionviewcell,Zposition,我正试图通过设置zPosition(如下面所示的代码中所示)将聚焦的collectionView单元格带到前面。但这似乎没有任何效果。请告诉我做这件事的正确程序 func collectionView(_ collectionView: UICollectionView, didUpdateFocusIn context: UICollectionViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {

我正试图通过设置zPosition(如下面所示的代码中所示)将聚焦的collectionView单元格带到前面。但这似乎没有任何效果。请告诉我做这件事的正确程序

 func collectionView(_ collectionView: UICollectionView, didUpdateFocusIn context: UICollectionViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
        if let prevIndexPath = context.previouslyFocusedIndexPath, let cell = collectionView.cellForItem(at: prevIndexPath) {
            cell.contentView.layer.zPosition = 0
        }
        
        if let indexPath = context.nextFocusedIndexPath,
            let cell = collectionView.cellForItem(at: indexPath) {
            cell.contentView.layer.zPosition = 1.0
            collectionView.scrollToItem(at: indexPath, at: [.centeredHorizontally, .centeredVertically], animated: true)
        }
    }

由于我试图在collectionViewCell中显示图像,因此不必设置zPosition,我们可以更改adjustsImageWhenAncestorFocused属性。我找到了同样的解决办法

我必须按如下方式设置imageview的adjustsImageWhenAncestorFocused属性:

func collectionView(_ collectionView: UICollectionView, didUpdateFocusIn context: UICollectionViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
        if let prevIndexPath = context.previouslyFocusedIndexPath, let cell = collectionView.cellForItem(at: prevIndexPath) {
                       cell.imageView.adjustsImageWhenAncestorFocused = false
        }
        
        if let indexPath = context.nextFocusedIndexPath,
            let cell = collectionView.cellForItem(at: indexPath) {
                       cell.imageView.adjustsImageWhenAncestorFocused = true
            collectionView.scrollToItem(at: indexPath, at: [.centeredHorizontally, .centeredVertically], animated: true)
        }
    }