44//
55
66import UIKit
7+ import SnappingLayout
78
89class SnappingPresentationViewController : UIViewController {
910
1011 // MARK: - Constants
1112
1213 private enum Constants {
13-
14+ static let cellReuseIdentifier = " cell "
15+ static let cellSize = CGSize ( width: 30 , height: 60 )
1416 }
1517
1618 // MARK: - Views
1719
20+ private lazy var collectionView : UICollectionView = {
21+ let layout = SnappingLayout ( )
22+ layout. snapPosition = self . snappingLayoutType
23+ layout. scrollDirection = . horizontal
24+ layout. itemSize = Constants . cellSize
25+ layout. minimumLineSpacing = 12
26+
27+ let collectionView = UICollectionView ( frame: . zero, collectionViewLayout: layout)
28+ collectionView. backgroundColor = . clear
29+ collectionView. showsHorizontalScrollIndicator = false
30+ collectionView. decelerationRate = . fast
31+ collectionView. register ( UICollectionViewCell . self, forCellWithReuseIdentifier: Constants . cellReuseIdentifier)
32+ return collectionView
33+ } ( )
34+
1835 // MARK: - Properties
1936
37+ private let snappingLayoutType : SnappingLayout . SnapPositionType
38+
39+ // MARK: - Initialization
40+
41+ init ( snappingLayoutType: SnappingLayout . SnapPositionType ) {
42+ self . snappingLayoutType = snappingLayoutType
43+ super. init ( nibName: nil , bundle: nil )
44+ }
45+
46+ required init ? ( coder _: NSCoder ) {
47+ fatalError ( " init(coder:) has not been implemented " )
48+ }
49+
2050 // MARK: - Life-cycle
2151
2252 override func viewDidLoad( ) {
@@ -31,9 +61,15 @@ class SnappingPresentationViewController: UIViewController {
3161private extension SnappingPresentationViewController {
3262
3363 func setupViews( ) {
64+ view. addSubview ( collectionView)
3465 }
3566
3667 func setupConstraints( ) {
68+ let collectionViewConstraints = [
69+ collectionView. centerYAnchor. constraint ( equalTo: view. centerYAnchor) ,
70+ collectionView. leftAnchor. constraint ( equalTo: view. leftAnchor) ,
71+ collectionView. rightAnchor. constraint ( equalTo: view. rightAnchor) ,
72+ ]
73+ NSLayoutConstraint . activate ( collectionViewConstraints)
3774 }
3875}
39-
0 commit comments