diff --git a/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard b/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard index be8e8c1..69957dd 100644 --- a/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard +++ b/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard @@ -36,7 +36,7 @@ - + diff --git a/UPCarouselFlowLayoutDemo/ViewController.swift b/UPCarouselFlowLayoutDemo/ViewController.swift index cd42f6c..4eb861e 100644 --- a/UPCarouselFlowLayoutDemo/ViewController.swift +++ b/UPCarouselFlowLayoutDemo/ViewController.swift @@ -8,7 +8,7 @@ import UIKit -class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { +class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UIScrollViewDelegate { @IBOutlet weak var infoLabel: UILabel! @IBOutlet weak var detailLabel: UILabel! @@ -91,7 +91,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CarouselCollectionViewCellIdentifier", for: indexPath) as! CarouselCollectionViewCell + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CarouselCollectionViewCell.identifier, for: indexPath) as! CarouselCollectionViewCell let character = items[indexPath.row] cell.image.image = UIImage(named: character.imageName) @@ -99,7 +99,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi return cell } - func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { let character = items[indexPath.row] let alert = UIAlertController(title: character.name, message: nil, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) @@ -109,7 +109,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi // MARK: - UIScrollViewDelegate - func scrollViewDidEndDecelerating(scrollView: UIScrollView) { + func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { let layout = self.collectionView.collectionViewLayout as! UPCarouselFlowLayout let pageSide = (layout.scrollDirection == .horizontal) ? self.pageSize.width : self.pageSize.height let offset = (layout.scrollDirection == .horizontal) ? scrollView.contentOffset.x : scrollView.contentOffset.y