Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Gardening
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman committed Dec 10, 2016
1 parent fca6773 commit a039415
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
9 changes: 6 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ included:
- PopsicleTests
disabled_rules:
- conditional_binding_cascade

force_cast: warning
force_try: warning
- force_cast
- force_try

leading_whitespace: warning
trailing_whitespace: warning

line_length:
warning: 175

function_body_length:
warning: 300
error: 400

type_body_length:
warning: 300
error: 400
Expand Down
22 changes: 10 additions & 12 deletions PopsicleDemo/PageScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@ class PageScrollView: DRPageScrollView {
let fourthPageView: FourthPageView

override init(frame: CGRect) {
let views = UIView.viewsByClassInNibNamed("PageViews")
self.firstPageView = views["PopsicleDemo.FirstPageView"] as! FirstPageView
self.secondPageView = views["PopsicleDemo.SecondPageView"] as! SecondPageView
self.thirdPageView = views["PopsicleDemo.ThirdPageView"] as! ThirdPageView
self.fourthPageView = views["PopsicleDemo.FourthPageView"] as! FourthPageView
let views = UIView.viewsByClassInNib(named: "PageViews")
firstPageView = views["PopsicleDemo.FirstPageView"] as! FirstPageView
secondPageView = views["PopsicleDemo.SecondPageView"] as! SecondPageView
thirdPageView = views["PopsicleDemo.ThirdPageView"] as! ThirdPageView
fourthPageView = views["PopsicleDemo.FourthPageView"] as! FourthPageView
super.init(frame: frame)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func didMoveToSuperview() {
if self.superview != nil {
for pv in [firstPageView, secondPageView, thirdPageView, fourthPageView] {
self.addPage { pageView in
if superview != nil {
[firstPageView, secondPageView, thirdPageView, fourthPageView].forEach { pv in
addPage { pageView in
pageView?.addSubview(pv)
pv.pinToSuperviewEdges()
}
}
}
}

@available(*, unavailable) required init?(coder aDecoder: NSCoder) { fatalError() }
}
11 changes: 5 additions & 6 deletions PopsicleDemo/UIView+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@
//

extension UIView {
static func viewsByClassInNibNamed(_ name: String) -> [String: UIView] {
static func viewsByClassInNib(named name: String) -> [String: UIView] {
guard let nibs = Bundle.main.loadNibNamed(name, owner: self, options: nil) else {
return [:]
}

return nibs
.filter { $0 is UIView }
.map { $0 as! UIView }
.flatMap { $0 as? UIView }
.map { (NSStringFromClass(type(of: $0)), $0) }
.reduce([String: UIView]()) { acc, element in
var acc = acc
acc[element.0] = element.1 as! UIView
acc[element.0] = element.1 as? UIView
return acc
}
}

func pinToSuperviewEdges() {
self.translatesAutoresizingMaskIntoConstraints = false
translatesAutoresizingMaskIntoConstraints = false

for attribute in [.top, .left, .bottom, .right] as [NSLayoutAttribute] {
let constraint = NSLayoutConstraint(item: self, attribute: attribute, relatedBy: .equal, toItem: self.superview, attribute: attribute, multiplier: 1, constant: 0)

self.superview?.addConstraint(constraint)
superview?.addConstraint(constraint)
}
}
}
32 changes: 16 additions & 16 deletions PopsicleDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class ViewController: UIViewController, UIScrollViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()

self.title = "Popsicle"
self.view.backgroundColor = .white
title = "Popsicle"
view.backgroundColor = .white

self.pageScrollView.delegate = self
self.view.addSubview(self.pageScrollView)
self.pageScrollView.pinToSuperviewEdges()
pageScrollView.delegate = self
view.addSubview(pageScrollView)
pageScrollView.pinToSuperviewEdges()
}

override func viewDidLayoutSubviews() {
Expand All @@ -31,26 +31,26 @@ class ViewController: UIViewController, UIScrollViewDelegate {
interpolations.removeAll()

let backgroundColorInterpolation = Interpolation(view, backgroundColor)
backgroundColorInterpolation[1, 3] = UIColor.white
backgroundColorInterpolation[1, 3] = .white
backgroundColorInterpolation[1.7, 2] = UIColor(red: 254/255, green: 134/255, blue: 44/255, alpha: 1)
interpolations.append(backgroundColorInterpolation)

let barTintColorInterpolation = Interpolation(navigationController!.navigationBar, barTintColor)
barTintColorInterpolation[1, 3] = UIColor.white
barTintColorInterpolation[1, 3] = .white
barTintColorInterpolation[1.7, 2] = UIColor(red: 244/255, green: 219/255, blue: 165/255, alpha: 1)
interpolations.append(barTintColorInterpolation)

if let imageView = self.pageScrollView.firstPageView.imageView {
if let imageView = pageScrollView.firstPageView.imageView {
let xInterpolation = Interpolation(imageView, centerXConstraint)
xInterpolation[f: 0] = (0, easeInQuad)
xInterpolation[1] = -self.pageScrollView.frame.width
xInterpolation[2] = -self.pageScrollView.frame.width*2
xInterpolation[3] = -self.pageScrollView.frame.width*3
xInterpolation[1] = -pageScrollView.frame.width
xInterpolation[2] = -pageScrollView.frame.width*2
xInterpolation[3] = -pageScrollView.frame.width*3
interpolations.append(xInterpolation)

let yInterpolation = Interpolation(imageView, centerYConstraint)
yInterpolation[0] = 0
yInterpolation[1, 2] = -self.pageScrollView.frame.height/2+80
yInterpolation[1, 2] = -pageScrollView.frame.height/2+80
yInterpolation[3] = 0
interpolations.append(yInterpolation)

Expand All @@ -67,14 +67,14 @@ class ViewController: UIViewController, UIScrollViewDelegate {
interpolations.append(transformInterpolation)
}

if let label1 = self.pageScrollView.firstPageView.label {
if let label1 = pageScrollView.firstPageView.label {
let alphaInterpolation = Interpolation(label1, alpha)
alphaInterpolation[0] = 1
alphaInterpolation[0.4] = 0
interpolations.append(alphaInterpolation)
}

if let label2 = self.pageScrollView.secondPageView.label {
if let label2 = pageScrollView.secondPageView.label {
let scaleInterpolation = Interpolation(label2, transform)
scaleInterpolation[0] = CGAffineTransform.identity.scaledBy(x: 0.6, y: 0.6)
scaleInterpolation[1] = .identity
Expand All @@ -86,7 +86,7 @@ class ViewController: UIViewController, UIScrollViewDelegate {
interpolations.append(alphaInterpolation)
}

if let label3 = self.pageScrollView.thirdPageView.label1, let label4 = self.pageScrollView.thirdPageView.label2 {
if let label3 = pageScrollView.thirdPageView.label1, let label4 = pageScrollView.thirdPageView.label2 {
let translateInterpolation1 = Interpolation(label3, transform)
translateInterpolation1[1] = CGAffineTransform.identity.translatedBy(x: 100, y: 0)
translateInterpolation1[2] = .identity
Expand All @@ -102,6 +102,6 @@ class ViewController: UIViewController, UIScrollViewDelegate {
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
interpolations.time = Double(scrollView.contentOffset.x/scrollView.frame.size.width)
interpolations.time = Time(scrollView.contentOffset.x/scrollView.frame.size.width)
}
}
2 changes: 1 addition & 1 deletion PopsicleTests/EasingFunctionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import XCTest
import Popsicle

infix operator ~= { }
infix operator ~=

func ~= <T: BinaryFloatingPoint>(lhs: T, rhs: T) -> Bool {
return abs(lhs - rhs) <= 0.02
Expand Down
2 changes: 1 addition & 1 deletion PopsicleTests/InterpolableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Popsicle

class InterpolableTests: XCTestCase {

class func test<I: Interpolable where I.ValueType == I>(initialValue: I, finalValue: I, interpolatedValues: [I], times: [Time], function: (I, I) -> Bool) {
class func test<I: Interpolable>(initialValue: I, finalValue: I, interpolatedValues: [I], times: [Time], function: (I, I) -> Bool) where I.ValueType == I {
for (index, time) in times.enumerated() {
let interpolatedValue = interpolatedValues[index]
let computedInterpolatedValue = I.interpolate(from: initialValue, to: finalValue, at: time)
Expand Down

0 comments on commit a039415

Please sign in to comment.