私が達成したいことは非常に単純です。ユーザーがコレクションビューセルにフォーカスするたびに、フォーカスされたセルを水平方向に中央揃えにしたいと考えています。私の現在のアプローチはまったく機能していないようです。
func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
guard collectionView === self.categoryCollectionView else {
return
}
guard let indexPath = context.nextFocusedIndexPath else {
return
}
collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .CenteredHorizontally, animated: true)
}
奇妙なのは、コレクション ビューがどこにスクロールしようとしても無視されることです。テスト目的で、インデックス パスをコレクション ビューの最後の項目のインデックス パスに変更しましたが、コレクション ビューが初めて表示されたときにのみ機能します。