複数のセルを含むコレクションビューがあります。ユーザーは水平方向にスクロールすることができます。しかし、一度ユーザーが移動できるようになると、最も近いセルを中央に配置したい。または、そうでない場合は、ページングの形式を個々のセルに対して行うことができます。私は基本的にアイコン/プロフィール画像ピッカーを作っています。コレクションビューでスティッキーな水平スクロール効果を作成する方法Swift 3
@IBOutlet weak var profilePicScrollView: UIScrollView!
var profilePicsArray = [#imageLiteral(resourceName: "sample_user_photo"), #imageLiteral(resourceName: "settings_icon"), #imageLiteral(resourceName: "usernametextfield_dark")]
@IBOutlet weak var profilePicCollectionView: UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return profilePicsArray.count
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionat section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageViewCellReuseID", for: indexPath) as! SettingsCollectionViewCell
cell.imageInCollection.image = profilePicsArray[indexPath.row]
cell.imageInCollection.backgroundColor = UIColor.getRandomColor()
return cell
}
私は実際にそれを試している途中でした!私は、親コレクションビュー(すなわち、継承以来のスクロールビュー)内の各セルの相対位置を取得する方法について固執しています。私はフレーム、境界、center.xを試しましたが、何も現在の位置を返すようです... – aoeuaoeu