0

私は主にビューの中央に1つの映画ポスターを表示したいコレクションビューを構築しました。コレクションビューには約20枚のムービーが表示されますので、右端に次のムービーを少し表示したいのですが、次のページに移動すると、フォーカスされたムービーが中央に表示されます次のムービーがそれぞれ左右に突き出しています。ページングを有効にしてUICollectionViewCellを水平に中央に配置するにはどうすればよいですか? (Swift)

私は自分のコードを持っているので、次のムービーにページすると、次のムービーはまったくセンタリングされず、x軸の右側に移動しすぎてしまいます。ページングに必要な距離をプログラムで設定するにはどうすればよいですか?最初の後にcollectionViewがページの中央を適切に配置できるようにするにはどうすればよいですか?

私のコレクションビューでページングが有効になっています。私はカスタムcollectionViewFlowLayoutを作成していません。ここで

Screenshots of my issue Video of my issue

私collectionViewとscrollViewコードです:

extension MainViewController: UICollectionViewDelegateFlowLayout { 
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
    let posterWidth = (collectionView.frame.size.height/3) * 2 
    return CGSizeMake(posterWidth, collectionView.frame.size.height) 
} 

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { 
    let posterWidth = (collectionView.frame.size.height/3) * 2 
    let horizontalInset = (collectionView.frame.size.width - posterWidth)/2 
    return UIEdgeInsetsMake(0, horizontalInset, 0, horizontalInset) 
} 

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { 
    return 20 
} 
} 

--------------- 

extension MainViewController: UIScrollViewDelegate { 
func scrollViewDidScroll(scrollView: UIScrollView) { 
    let index = Int(collectionView.contentOffset.x/collectionView.frame.size.width) 
    let movie = movies[index] 
    updateViews(movie) 
} 
} 

答えて

1

[yourCollectionView setPagingEnabled:YES]; 
を使用してみてください
関連する問題