Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</userDefinedRuntimeAttributes>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="CarouselCollectionViewCellIdentifier" id="ogm-oB-jCJ" customClass="CarouselCollectionViewCell" customModule="UPCarouselFlowLayoutDemo" customModuleProvider="target">
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="CarouselCollectionViewCell" id="ogm-oB-jCJ" customClass="CarouselCollectionViewCell" customModule="UPCarouselFlowLayoutDemo" customModuleProvider="target">
<rect key="frame" x="0.0" y="90" width="200" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
Expand Down
8 changes: 4 additions & 4 deletions UPCarouselFlowLayoutDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -91,15 +91,15 @@ 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)

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))
Expand All @@ -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
Expand Down