From 8db28635ac313fa5d3287b1a0147869457c3ee6d Mon Sep 17 00:00:00 2001 From: Mariam Date: Wed, 31 Aug 2016 21:36:46 +0300 Subject: [PATCH 1/4] Removed autolayout warning --- .../Base.lproj/Main.storyboard | 188 +++++++++--------- 1 file changed, 90 insertions(+), 98 deletions(-) diff --git a/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard b/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard index 4356cdf..4c00edc 100644 --- a/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard +++ b/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -7,21 +7,21 @@ - + - + - - + + - + - + - - + + @@ -36,14 +36,14 @@ - + - + @@ -51,134 +51,126 @@ - - - - + + + + - + - - + + - + - - + + - - + - - + + - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - + + + - + From 97e985a7e5d03897efec6b5d2e36239542635b74 Mon Sep 17 00:00:00 2001 From: Arthur Chambriard Date: Thu, 15 Sep 2016 14:29:03 +0200 Subject: [PATCH 2/4] Update swift3 --- .../UPCarouselFlowLayout.swift | 36 +++++++++--------- .../project.pbxproj | 14 ++++++- .../AppIcon.appiconset/Contents.json | 10 +++++ .../Base.lproj/LaunchScreen.storyboard | 13 ++++--- .../CarouselCollectionViewCell.swift | 2 +- UPCarouselFlowLayoutDemo/GradientView.swift | 20 +++++----- UPCarouselFlowLayoutDemo/ViewController.swift | 38 +++++++++++-------- 7 files changed, 80 insertions(+), 53 deletions(-) diff --git a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift index dad4154..6da33cb 100644 --- a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift +++ b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift @@ -21,7 +21,7 @@ public class UPCarouselFlowLayout: UICollectionViewFlowLayout { var size: CGSize var direction: UICollectionViewScrollDirection func isEqual(otherState: LayoutState) -> Bool { - return CGSizeEqualToSize(self.size, otherState.size) && self.direction == otherState.direction + return self.size.equalTo(otherState.size) && self.direction == otherState.direction } } @@ -29,15 +29,15 @@ public class UPCarouselFlowLayout: UICollectionViewFlowLayout { @IBInspectable public var sideItemAlpha: CGFloat = 0.6 public var spacingMode = UPCarouselFlowLayoutSpacingMode.fixed(spacing: 40) - private var state = LayoutState(size: CGSizeZero, direction: .Horizontal) + private var state = LayoutState(size: CGSize.zero, direction: .horizontal) - override public func prepareLayout() { - super.prepareLayout() + override public func prepare() { + super.prepare() let currentState = LayoutState(size: self.collectionView!.bounds.size, direction: self.scrollDirection) - if !self.state.isEqual(currentState) { + if !self.state.isEqual(otherState: currentState) { self.setupCollectionView() self.updateLayout() self.state = currentState @@ -55,7 +55,7 @@ public class UPCarouselFlowLayout: UICollectionViewFlowLayout { guard let collectionView = self.collectionView else { return } let collectionSize = collectionView.bounds.size - let isHorizontal = (self.scrollDirection == .Horizontal) + let isHorizontal = (self.scrollDirection == .horizontal) let yInset = (collectionSize.height - self.itemSize.height) / 2 let xInset = (collectionSize.width - self.itemSize.width) / 2 @@ -73,20 +73,20 @@ public class UPCarouselFlowLayout: UICollectionViewFlowLayout { } } - override public func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool { + override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { return true } - override public func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - guard let superAttributes = super.layoutAttributesForElementsInRect(rect), + override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + guard let superAttributes = super.layoutAttributesForElements(in: rect), let attributes = NSArray(array: superAttributes, copyItems: true) as? [UICollectionViewLayoutAttributes] else { return nil } - return attributes.map({ self.transformLayoutAttributes($0) }) + return attributes.map({ self.transformLayoutAttributes(attributes: $0) }) } private func transformLayoutAttributes(attributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { guard let collectionView = self.collectionView else { return attributes } - let isHorizontal = (self.scrollDirection == .Horizontal) + let isHorizontal = (self.scrollDirection == .horizontal) let collectionCenter = isHorizontal ? collectionView.frame.size.width/2 : collectionView.frame.size.height/2 let offset = isHorizontal ? collectionView.contentOffset.x : collectionView.contentOffset.y @@ -104,23 +104,23 @@ public class UPCarouselFlowLayout: UICollectionViewFlowLayout { return attributes } - override public func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint { - guard let collectionView = collectionView where !collectionView.pagingEnabled, - let layoutAttributes = self.layoutAttributesForElementsInRect(collectionView.bounds) - else { return super.targetContentOffsetForProposedContentOffset(proposedContentOffset) } + override public func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint { + guard let collectionView = collectionView , !collectionView.isPagingEnabled, + let layoutAttributes = self.layoutAttributesForElements(in: collectionView.bounds) + else { return super.targetContentOffset(forProposedContentOffset: proposedContentOffset) } - let isHorizontal = (self.scrollDirection == .Horizontal) + let isHorizontal = (self.scrollDirection == .horizontal) let midSide = (isHorizontal ? collectionView.bounds.size.width : collectionView.bounds.size.height) / 2 let proposedContentOffsetCenterOrigin = (isHorizontal ? proposedContentOffset.x : proposedContentOffset.y) + midSide var targetContentOffset: CGPoint if isHorizontal { - let closest = layoutAttributes.sort { abs($0.center.x - proposedContentOffsetCenterOrigin) < abs($1.center.x - proposedContentOffsetCenterOrigin) }.first ?? UICollectionViewLayoutAttributes() + let closest = layoutAttributes.sorted { abs($0.center.x - proposedContentOffsetCenterOrigin) < abs($1.center.x - proposedContentOffsetCenterOrigin) }.first ?? UICollectionViewLayoutAttributes() targetContentOffset = CGPoint(x: floor(closest.center.x - midSide), y: proposedContentOffset.y) } else { - let closest = layoutAttributes.sort { abs($0.center.y - proposedContentOffsetCenterOrigin) < abs($1.center.y - proposedContentOffsetCenterOrigin) }.first ?? UICollectionViewLayoutAttributes() + let closest = layoutAttributes.sorted { abs($0.center.y - proposedContentOffsetCenterOrigin) < abs($1.center.y - proposedContentOffsetCenterOrigin) }.first ?? UICollectionViewLayoutAttributes() targetContentOffset = CGPoint(x: proposedContentOffset.x, y: floor(closest.center.y - midSide)) } diff --git a/UPCarouselFlowLayoutDemo.xcodeproj/project.pbxproj b/UPCarouselFlowLayoutDemo.xcodeproj/project.pbxproj index 0b7077a..98e0ed1 100644 --- a/UPCarouselFlowLayoutDemo.xcodeproj/project.pbxproj +++ b/UPCarouselFlowLayoutDemo.xcodeproj/project.pbxproj @@ -111,12 +111,13 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Paul Ulric"; TargetAttributes = { 01D3876A1D1C4B9D00CE4E1F = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = 5LPW7LLHS8; + DevelopmentTeam = 79S2A7FTB9; + LastSwiftMigration = 0800; }; }; }; @@ -201,8 +202,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -246,8 +249,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -266,6 +271,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -274,10 +280,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 79S2A7FTB9; INFOPLIST_FILE = UPCarouselFlowLayoutDemo/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = UP.UPCarouselFlowLayoutDemo; PRODUCT_NAME = UPCarouselFlowLayoutDemo; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -285,10 +293,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 79S2A7FTB9; INFOPLIST_FILE = UPCarouselFlowLayoutDemo/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = UP.UPCarouselFlowLayoutDemo; PRODUCT_NAME = UPCarouselFlowLayoutDemo; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/UPCarouselFlowLayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/UPCarouselFlowLayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json index 118c98f..b8236c6 100644 --- a/UPCarouselFlowLayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/UPCarouselFlowLayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", diff --git a/UPCarouselFlowLayoutDemo/Base.lproj/LaunchScreen.storyboard b/UPCarouselFlowLayoutDemo/Base.lproj/LaunchScreen.storyboard index 2e721e1..07213a4 100644 --- a/UPCarouselFlowLayoutDemo/Base.lproj/LaunchScreen.storyboard +++ b/UPCarouselFlowLayoutDemo/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,9 @@ - - + + - + + + @@ -13,10 +15,9 @@ - + - - + diff --git a/UPCarouselFlowLayoutDemo/CarouselCollectionViewCell.swift b/UPCarouselFlowLayoutDemo/CarouselCollectionViewCell.swift index 6e6fff3..15b9001 100644 --- a/UPCarouselFlowLayoutDemo/CarouselCollectionViewCell.swift +++ b/UPCarouselFlowLayoutDemo/CarouselCollectionViewCell.swift @@ -17,6 +17,6 @@ class CarouselCollectionViewCell: UICollectionViewCell { self.layer.cornerRadius = max(self.frame.size.width, self.frame.size.height) / 2 self.layer.borderWidth = 10 - self.layer.borderColor = UIColor(red: 110.0/255.0, green: 80.0/255.0, blue: 140.0/255.0, alpha: 1.0).CGColor + self.layer.borderColor = UIColor(red: 110.0/255.0, green: 80.0/255.0, blue: 140.0/255.0, alpha: 1.0).cgColor } } diff --git a/UPCarouselFlowLayoutDemo/GradientView.swift b/UPCarouselFlowLayoutDemo/GradientView.swift index 9107ee4..57631ed 100644 --- a/UPCarouselFlowLayoutDemo/GradientView.swift +++ b/UPCarouselFlowLayoutDemo/GradientView.swift @@ -10,22 +10,22 @@ import UIKit class GradientView: UIView { - override func drawRect(rect: CGRect) { - let colorSpace: CGColorSpaceRef = CGColorSpaceCreateDeviceRGB()! - let context: CGContextRef = UIGraphicsGetCurrentContext()! - CGContextSaveGState(context) + override func draw(_ rect: CGRect) { + let colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB() + let context: CGContext = UIGraphicsGetCurrentContext()! + context.saveGState() let startColor: UIColor = UIColor(red: 79.0/255.0, green: 30.0/255.0, blue: 122.0/255.0, alpha: 1.0) let endColor: UIColor = UIColor(red: 46.0/255.0, green: 12.0/255.0, blue: 80.0/255.0, alpha: 1.0) - let colors = [startColor.CGColor, endColor.CGColor] + let colors = [startColor.cgColor, endColor.cgColor] let locations: [CGFloat] = [0, 1] - let gradient: CGGradientRef = CGGradientCreateWithColors(colorSpace, colors, locations)! + let gradient: CGGradient = CGGradient(colorsSpace: colorSpace, colors: colors as CFArray, locations: locations)! - let startPoint: CGPoint = CGPoint(x:CGRectGetMidX(rect), y: CGRectGetMinY(rect)) - let endPoint: CGPoint = CGPoint(x: CGRectGetMidX(rect), y: CGRectGetMaxY(rect)) + let startPoint: CGPoint = CGPoint(x:rect.midX, y: rect.minY) + let endPoint: CGPoint = CGPoint(x: rect.midX, y: rect.maxY) - CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, []) - CGContextRestoreGState(context) + context.drawLinearGradient(gradient, start: startPoint, end: endPoint, options: []) + context.restoreGState() } } diff --git a/UPCarouselFlowLayoutDemo/ViewController.swift b/UPCarouselFlowLayoutDemo/ViewController.swift index 7e3f96c..7b07f44 100644 --- a/UPCarouselFlowLayoutDemo/ViewController.swift +++ b/UPCarouselFlowLayoutDemo/ViewController.swift @@ -9,6 +9,12 @@ import UIKit class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { + @available(iOS 6.0, *) + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + //NOT IMPLEMENTED + return UICollectionViewCell() + } + @IBOutlet weak var infoLabel: UILabel! @IBOutlet weak var detailLabel: UILabel! @@ -19,15 +25,15 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi private var currentPage: Int = 0 { didSet { let character = self.items[self.currentPage] - self.infoLabel.text = character.name.uppercaseString - self.detailLabel.text = character.movie.uppercaseString + self.infoLabel.text = character.name.uppercased() + self.detailLabel.text = character.movie.uppercased() } } private var pageSize: CGSize { let layout = self.collectionView.collectionViewLayout as! UPCarouselFlowLayout var pageSize = layout.itemSize - if layout.scrollDirection == .Horizontal { + if layout.scrollDirection == .horizontal { pageSize.width += layout.minimumLineSpacing } else { pageSize.height += layout.minimumLineSpacing @@ -36,7 +42,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi } private var orientation: UIDeviceOrientation { - return UIDevice.currentDevice().orientation + return UIDevice.current.orientation } @@ -48,7 +54,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi self.currentPage = 0 - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.rotationDidChange), name: UIDeviceOrientationDidChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(ViewController.rotationDidChange), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) } private func setupLayout() { @@ -71,12 +77,12 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi @objc private func rotationDidChange() { let layout = self.collectionView.collectionViewLayout as! UPCarouselFlowLayout - let direction: UICollectionViewScrollDirection = UIDeviceOrientationIsPortrait(orientation) ? .Horizontal : .Vertical + let direction: UICollectionViewScrollDirection = UIDeviceOrientationIsPortrait(orientation) ? .horizontal : .vertical layout.scrollDirection = direction if currentPage > 0 { - let indexPath = NSIndexPath(forItem: currentPage, inSection: 0) - let scrollPosition: UICollectionViewScrollPosition = UIDeviceOrientationIsPortrait(orientation) ? .CenteredHorizontally : .CenteredVertically - self.collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: scrollPosition, animated: false) + let indexPath = NSIndexPath(item: currentPage, section: 0) + let scrollPosition: UICollectionViewScrollPosition = UIDeviceOrientationIsPortrait(orientation) ? .centeredHorizontally : .centeredVertically + self.collectionView.scrollToItem(at: indexPath as IndexPath, at: scrollPosition, animated: false) } } @@ -86,12 +92,12 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi return 1 } - func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return items.count } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier(CarouselCollectionViewCell.identifier, forIndexPath: indexPath) as! CarouselCollectionViewCell + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CarouselCollectionViewCell.identifier, for: indexPath as IndexPath) as! CarouselCollectionViewCell let character = items[indexPath.row] cell.image.image = UIImage(named: character.imageName) return cell @@ -99,9 +105,9 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { let character = items[indexPath.row] - let alert = UIAlertController(title: character.name, message: nil, preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) - presentViewController(alert, animated: true, completion: nil) + let alert = UIAlertController(title: character.name, message: nil, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) + present(alert, animated: true, completion: nil) } @@ -109,8 +115,8 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi 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 + let pageSide = (layout.scrollDirection == .horizontal) ? self.pageSize.width : self.pageSize.height + let offset = (layout.scrollDirection == .horizontal) ? scrollView.contentOffset.x : scrollView.contentOffset.y currentPage = Int(floor((offset - pageSide / 2) / pageSide) + 1) } From e2b2e948aba56630121639d1672107c326b644c0 Mon Sep 17 00:00:00 2001 From: Arthur Chambriard Date: Thu, 15 Sep 2016 15:30:49 +0200 Subject: [PATCH 3/4] Bug fix --- .../Base.lproj/Main.storyboard | 74 +++++++++---------- UPCarouselFlowLayoutDemo/ViewController.swift | 14 ++-- 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard b/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard index 4c00edc..be8e8c1 100644 --- a/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard +++ b/UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard @@ -1,9 +1,10 @@ - - + + - + + @@ -15,12 +16,11 @@ - + - - + @@ -36,20 +36,17 @@ - - + + - - - + - - + @@ -66,35 +63,32 @@ - - + + - - + - + @@ -123,44 +117,44 @@ - - - + + + - - - - + + + + - - + - + + + - - - + - + + - - + + + + - - diff --git a/UPCarouselFlowLayoutDemo/ViewController.swift b/UPCarouselFlowLayoutDemo/ViewController.swift index 7b07f44..cd42f6c 100644 --- a/UPCarouselFlowLayoutDemo/ViewController.swift +++ b/UPCarouselFlowLayoutDemo/ViewController.swift @@ -9,12 +9,6 @@ import UIKit class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { - @available(iOS 6.0, *) - public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - //NOT IMPLEMENTED - return UICollectionViewCell() - } - @IBOutlet weak var infoLabel: UILabel! @IBOutlet weak var detailLabel: UILabel! @@ -88,7 +82,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi // MARK: - Card Collection Delegate & DataSource - func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } @@ -96,10 +90,12 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi return items.count } - func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CarouselCollectionViewCell.identifier, for: indexPath as IndexPath) as! CarouselCollectionViewCell + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CarouselCollectionViewCellIdentifier", for: indexPath) as! CarouselCollectionViewCell + let character = items[indexPath.row] cell.image.image = UIImage(named: character.imageName) + return cell } From 86110e9b60c815c9c3042481f7d67c68b0ee336a Mon Sep 17 00:00:00 2001 From: Arthur Chambriard Date: Thu, 15 Sep 2016 16:28:17 +0200 Subject: [PATCH 4/4] Bug fix --- UPCarouselFlowLayoutDemo/Base.lproj/Main.storyboard | 2 +- UPCarouselFlowLayoutDemo/ViewController.swift | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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