Skip to content

Commit

Permalink
Expose scale, alpha related values, allow overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
aataraxiaa committed Apr 1, 2018
1 parent 04bf9a7 commit eebd135
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions ScalingCarousel/Classes/ScalingCarouselCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ import UIKit
*/
open class ScalingCarouselCell: UICollectionViewCell {

// MARK: - Properties (Public)

/// The minimum value to scale to, should be set between 0 and 1
open var scaleMinimum: CGFloat = 0.9

/// Divisior used when calculating the scale value.
/// Lower values cause a greater difference in scale between subsequent cells.
open var scaleDivisor: CGFloat = 10.0

/// The minimum value to alpha to, should be set between 0 and 1
open var alphaMinimum: CGFloat = 0.85

// MARK: - IBOutlets

// This property should be connected to the main cell subview
@IBOutlet public var mainView: UIView!

private struct InternalConstants {
static let alphaSmallestValue: CGFloat = 0.85
static let scaleDivisor: CGFloat = 10.0
}

// MARK: - Overrides

override open func layoutSubviews() {
Expand All @@ -49,10 +56,7 @@ open class ScalingCarouselCell: UICollectionViewCell {
/// Scale the cell when it is scrolled
///
/// - parameter carouselInset: The inset of the related SPBCarousel view
/// - parameter scaleMinimum: The minimun % a cell should scale to,
/// expressed as a value between 0.0 and 1.0
open func scale(withCarouselInset carouselInset: CGFloat,
scaleMinimum: CGFloat = 0.9) {
open func scale(withCarouselInset carouselInset: CGFloat) {

// Ensure we have a superView, and mainView
guard let superview = superview,
Expand All @@ -71,10 +75,10 @@ open class ScalingCarouselCell: UICollectionViewCell {
let percentageScale = (scaleCalculator/width)

let scaleValue = scaleMinimum
+ (percentageScale/InternalConstants.scaleDivisor)
+ (percentageScale/scaleDivisor)

let alphaValue = InternalConstants.alphaSmallestValue
+ (percentageScale/InternalConstants.scaleDivisor)
let alphaValue = alphaMinimum
+ (percentageScale/scaleDivisor)

let affineIdentity = CGAffineTransform.identity

Expand Down

0 comments on commit eebd135

Please sign in to comment.