imageArray = ["one"、 "two"、... "eight"]という配列があります。そして、コレクションビューに画像を埋め込みます。前提条件:セルはビューの中央に配置され、コレクションビュー/ビューの大半を占めます。画像ビューは一番上にあり、セルより少し小さいです。わかりましたので、今私はユーザーがどちらの画像をカウントする必要があります。ユーザーが画像3にスクロールすると、3をカウントする方法が必要になります。コレクションビューでは、ちょうどそれらについて見つかったので、いくつかの助けが必要です。ここ は、あなたが何をすべきいくつかのコード(基本設定)どの画像ユーザが水平コレクションビューでページングを有効にしているかをカウントする
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var myCollectionView: UICollectionView!
@IBOutlet var mainView: UIView!
var imageArray = ["one", "two", "three", "four", "five", "six", "seven", "eight"]
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! UserFeedCollectionViewCell
cell.myImage.image = UIImage(named: imageArray[indexPath.row])
cell.myImage.layer.cornerRadius = 12.0
cell.myImage.clipsToBounds = true
return cell
}
このリンクを参照してください。 http://stackoverflow.com/questions/18649920/uicollectionview-current-visible-cell-index –