当前位置:  开发笔记 > 编程语言 > 正文

突出显示当前的UICollectionViewCell tvOS

如何解决《突出显示当前的UICollectionViewCelltvOS》经验,为你挑选了1个好方法。



1> 小智..:

您可以使用collectionview Delegate方法,方法名称是

func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) 
{
}

您可以像这样使用此方法......

func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {

    if let previousIndexPath = context.previouslyFocusedIndexPath,
        let cell = collectionView.cellForItemAtIndexPath(previousIndexPath) {
        cell.contentView.layer.borderWidth = 0.0
        cell.contentView.layer.shadowRadius = 0.0
        cell.contentView.layer.shadowOpacity = 0
    }

    if let indexPath = context.nextFocusedIndexPath,
        let cell = collectionView.cellForItemAtIndexPath(indexPath) {
        cell.contentView.layer.borderWidth = 8.0
        cell.contentView.layer.borderColor = UIColor.blackColor().CGColor
        cell.contentView.layer.shadowColor = UIColor.blackColor().CGColor
        cell.contentView.layer.shadowRadius = 10.0
        cell.contentView.layer.shadowOpacity = 0.9
        cell.contentView.layer.shadowOffset = CGSize(width: 0, height: 0)
        collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: [.CenteredHorizontally, .CenteredVertically], animated: true)
    }
}

推荐阅读
yzh148448
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有