您可以使用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) } }