Skip to content

Commit 8a89419

Browse files
author
andrewtweber
committed
Text files and comments
1 parent e7c82fe commit 8a89419

20 files changed

+152
-76
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014 André Schneider <hello@andreschneider.me>
1+
Copyright (c) 2018 Andrew Weber
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Popping/Controls/CircleView.swift

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class CircleView: UIView
2424
super.init(coder: aDecoder)
2525
}
2626

27+
// MARK: - Property setters
28+
2729
func setStrokeEnd(_ strokeEnd: CGFloat, animated: Bool) {
2830
if (animated) {
2931
self.animateToStrokeEnd(strokeEnd)
@@ -37,6 +39,8 @@ class CircleView: UIView
3739
self.strokeColor = strokeColor
3840
}
3941

42+
// MARK: - Private instance methods
43+
4044
private func addCircleLayer() {
4145
let lineWidth: CGFloat = 4
4246
let radius: CGFloat = self.bounds.width / 2 - lineWidth / 2

Popping/Controls/FlatButton.swift

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class FlatButton: UIButton
4040
height: s.height + self.titleEdgeInsets.top + self.titleEdgeInsets.bottom)
4141
}
4242

43+
// MARK: - Private instance methods
44+
4345
private func setup() {
4446
self.backgroundColor = self.tintColor
4547
self.layer.cornerRadius = 4
@@ -51,6 +53,8 @@ class FlatButton: UIButton
5153
addTarget(self, action: #selector(scaleToDefault), for: .touchDragExit)
5254
}
5355

56+
// MARK: - Animations
57+
5458
@objc private func scaleToSmall() {
5559
if let scaleAnimation = POPBasicAnimation(propertyNamed: kPOPLayerScaleXY) {
5660
scaleAnimation.toValue = CGSize(width: 0.95, height: 0.95)

Popping/Controls/FoldingView.swift

+43-35
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class FoldingView: UIView
3636
super.init(coder: aDecoder)
3737
}
3838

39+
// MARK: - Private instance methods
40+
3941
private func addTopView() {
4042
let image: UIImage = self.imageForSection(.top, withImage: self.image)
4143

@@ -93,6 +95,43 @@ class FoldingView: UIView
9395
self.rotateToOriginWithVelocity(5)
9496
}
9597

98+
private func transform3D() -> CATransform3D {
99+
var transform: CATransform3D = CATransform3DIdentity
100+
transform.m34 = 2.5 / -2000
101+
return transform
102+
}
103+
104+
private func isLocation(_ location: CGPoint, inView view: UIView) -> Bool {
105+
if ((location.x > 0 && location.x < self.bounds.width) &&
106+
(location.y > 0 && location.y < self.bounds.height)) {
107+
return true
108+
}
109+
110+
return false
111+
}
112+
113+
private func imageForSection(_ section: LayerSection, withImage image: UIImage) -> UIImage {
114+
var rect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height / 2)
115+
if (section == .bottom) {
116+
rect.origin.y = image.size.height / 2
117+
}
118+
119+
let imgRef = image.cgImage?.cropping(to: rect)
120+
let imagePart = UIImage(cgImage: imgRef!)
121+
return imagePart
122+
}
123+
124+
private func maskForSection(_ section: LayerSection, withRect rect: CGRect) -> CAShapeLayer {
125+
let layerMask = CAShapeLayer()
126+
let corners = UIRectCorner(rawValue: section == .top ? 3 : 12)
127+
128+
let size = CGSize(width: 5, height: 5)
129+
layerMask.path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: size).cgPath
130+
return layerMask
131+
}
132+
133+
// MARK: - Event handlers
134+
96135
@objc private func handlePan(_ recognizer: UIPanGestureRecognizer) {
97136
let location: CGPoint = recognizer.location(in: self)
98137

@@ -139,6 +178,8 @@ class FoldingView: UIView
139178
}
140179
}
141180

181+
// MARK: - Animations
182+
142183
private func rotateToOriginWithVelocity(_ velocity: CGFloat) {
143184
if let rotationAnimation = POPSpringAnimation(propertyNamed: kPOPLayerRotationX) {
144185
if (velocity > 0) {
@@ -153,43 +194,10 @@ class FoldingView: UIView
153194
self.topView.layer.pop_add(rotationAnimation, forKey: "rotationAnimation")
154195
}
155196
}
156-
157-
private func transform3D() -> CATransform3D {
158-
var transform: CATransform3D = CATransform3DIdentity
159-
transform.m34 = 2.5 / -2000
160-
return transform
161-
}
162-
163-
private func isLocation(_ location: CGPoint, inView view: UIView) -> Bool {
164-
if ((location.x > 0 && location.x < self.bounds.width) &&
165-
(location.y > 0 && location.y < self.bounds.height)) {
166-
return true
167-
}
168-
169-
return false
170-
}
171-
172-
private func imageForSection(_ section: LayerSection, withImage image: UIImage) -> UIImage {
173-
var rect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height / 2)
174-
if (section == .bottom) {
175-
rect.origin.y = image.size.height / 2
176-
}
177-
178-
let imgRef = image.cgImage?.cropping(to: rect)
179-
let imagePart = UIImage(cgImage: imgRef!)
180-
return imagePart
181-
}
182-
183-
private func maskForSection(_ section: LayerSection, withRect rect: CGRect) -> CAShapeLayer {
184-
let layerMask = CAShapeLayer()
185-
let corners = UIRectCorner(rawValue: section == .top ? 3 : 12)
186-
187-
let size = CGSize(width: 5, height: 5)
188-
layerMask.path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: size).cgPath
189-
return layerMask
190-
}
191197
}
192198

199+
// MARK: - pop Animation delegate
200+
193201
extension FoldingView: POPAnimationDelegate
194202
{
195203
func pop_animationDidApply(_ anim: POPAnimation!) {

Popping/Controls/ImageView.swift

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class ImageView: UIControl
2626
super.init(coder: aDecoder)
2727
}
2828

29+
// MARK: - Property setters
30+
2931
func setImage(_ image: UIImage) {
3032
self.imageView.image = image
3133
self.image = image

Popping/Controls/PaperButton.swift

+46-38
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,59 @@ class PaperButton: UIControl
3333
super.init(coder: aDecoder)
3434
}
3535

36+
// MARK: - Instance methods
37+
3638
override func tintColorDidChange() {
3739
let color = self.tintColor.cgColor
3840
self.topLayer.backgroundColor = color
3941
self.middleLayer.backgroundColor = color
4042
self.bottomLayer.backgroundColor = color
4143
}
4244

45+
// MARK: - Private instance methods
46+
47+
func setup() {
48+
let height: CGFloat = 2
49+
let width: CGFloat = self.bounds.width
50+
let cornerRadius: CGFloat = 1
51+
let color: CGColor = self.tintColor.cgColor
52+
53+
self.topLayer = CALayer()
54+
self.topLayer.frame = CGRect(x: 0, y: self.bounds.minY, width: width, height: height)
55+
self.topLayer.cornerRadius = cornerRadius
56+
self.topLayer.backgroundColor = color
57+
58+
self.middleLayer = CALayer()
59+
self.middleLayer.frame = CGRect(x: 0, y: self.bounds.midY - height/2, width: width, height: height)
60+
self.middleLayer.cornerRadius = cornerRadius
61+
self.middleLayer.backgroundColor = color
62+
63+
self.bottomLayer = CALayer()
64+
self.bottomLayer.frame = CGRect(x: 0, y: self.bounds.maxY - height, width: width, height: height)
65+
self.bottomLayer.cornerRadius = cornerRadius
66+
self.bottomLayer.backgroundColor = color
67+
68+
self.layer.addSublayer(self.topLayer)
69+
self.layer.addSublayer(self.middleLayer)
70+
self.layer.addSublayer(self.bottomLayer)
71+
72+
self.addTarget(self, action: #selector(touchUpInsideHandler), for: .touchUpInside)
73+
}
74+
75+
// MARK: - Event handlers
76+
77+
@objc func touchUpInsideHandler(_ sender: PaperButton) {
78+
if (self.showMenu) {
79+
self.animateToMenu()
80+
} else {
81+
self.animateToClose()
82+
}
83+
84+
self.showMenu = !self.showMenu
85+
}
86+
87+
// MARK: - Animations
88+
4389
func animateToMenu() {
4490
self.removeAllAnimations()
4591

@@ -112,44 +158,6 @@ class PaperButton: UIControl
112158
}
113159
}
114160

115-
func setup() {
116-
let height: CGFloat = 2
117-
let width: CGFloat = self.bounds.width
118-
let cornerRadius: CGFloat = 1
119-
let color: CGColor = self.tintColor.cgColor
120-
121-
self.topLayer = CALayer()
122-
self.topLayer.frame = CGRect(x: 0, y: self.bounds.minY, width: width, height: height)
123-
self.topLayer.cornerRadius = cornerRadius
124-
self.topLayer.backgroundColor = color
125-
126-
self.middleLayer = CALayer()
127-
self.middleLayer.frame = CGRect(x: 0, y: self.bounds.midY - height/2, width: width, height: height)
128-
self.middleLayer.cornerRadius = cornerRadius
129-
self.middleLayer.backgroundColor = color
130-
131-
self.bottomLayer = CALayer()
132-
self.bottomLayer.frame = CGRect(x: 0, y: self.bounds.maxY - height, width: width, height: height)
133-
self.bottomLayer.cornerRadius = cornerRadius
134-
self.bottomLayer.backgroundColor = color
135-
136-
self.layer.addSublayer(self.topLayer)
137-
self.layer.addSublayer(self.middleLayer)
138-
self.layer.addSublayer(self.bottomLayer)
139-
140-
self.addTarget(self, action: #selector(touchUpInsideHandler), for: .touchUpInside)
141-
}
142-
143-
@objc func touchUpInsideHandler(_ sender: PaperButton) {
144-
if (self.showMenu) {
145-
self.animateToMenu()
146-
} else {
147-
self.animateToClose()
148-
}
149-
150-
self.showMenu = !self.showMenu
151-
}
152-
153161
func removeAllAnimations() {
154162
self.topLayer.pop_removeAllAnimations()
155163
self.middleLayer.pop_removeAllAnimations()

Popping/Controls/PasswordStrengthIndicatorView.swift

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class PasswordStrengthIndicatorView: UIView
4141
super.init(coder: aDecoder)
4242
}
4343

44+
// MARK: - Private instance methods
45+
4446
func animateIndicatorViewToStatus(_ status: PasswordStrengthIndicatorViewStatus) {
4547
let constraints = self.constraints.enumerated()
4648
for constraint in constraints {

Popping/Extensions/UIColor.swift

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extension UIColor
1818
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
1919
}
2020

21+
// MARK: - Custom colors
22+
2123
class var customGray: UIColor {
2224
return UIColor(red: 84, green: 84, blue: 84)
2325
}

Popping/ViewControllers/AnimationsListViewController.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ class AnimationsListViewController: UITableViewController
2121
self.configureTitleView()
2222
}
2323

24+
// MARK: - Table view delegate
25+
2426
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
2527
let viewController = self.viewController(forRowAt: indexPath)
2628
viewController.title = self.title(forRowAt: indexPath)
2729
self.navigationController?.pushViewController(viewController, animated: true)
2830
}
2931

32+
// MARK: - Table view data source
33+
3034
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
3135
return self.titles.count
3236
}
@@ -37,6 +41,8 @@ class AnimationsListViewController: UITableViewController
3741
return cell
3842
}
3943

44+
// MARK: - Private instance methods
45+
4046
private func configureTableView() {
4147
self.titles = [
4248
"Button Animation",
@@ -66,6 +72,7 @@ class AnimationsListViewController: UITableViewController
6672
self.tableView.rowHeight = 50
6773
}
6874

75+
// Makes the letter "o" blue while the rest of "popping" is gray
6976
private func configureTitleView() {
7077
let headlineLabel = UILabel()
7178
headlineLabel.font = UIFont(name: "Avenir-Light", size: 28)
@@ -76,7 +83,6 @@ class AnimationsListViewController: UITableViewController
7683
NSAttributedString.Key.foregroundColor: UIColor.customBlue,
7784
]
7885

79-
// TODO this isn't working
8086
let attributedString = NSMutableAttributedString(string: self.title!)
8187
attributedString.addAttributes(attributes, range: NSRange(location: 1, length: 1))
8288
headlineLabel.attributedText = attributedString

Popping/ViewControllers/ButtonViewController.swift

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class ButtonViewController: UIViewController
2323
self.addActivityIndicatorView()
2424
}
2525

26+
// MARK: - Private instance methods
27+
2628
private func addButton() {
2729
self.button = FlatButton()
2830
self.button.backgroundColor = .customBlue
@@ -78,6 +80,8 @@ class ButtonViewController: UIViewController
7880
}
7981
}
8082

83+
// MARK: - Animations
84+
8185
func shakeButton() {
8286
if let positionAnimation = POPSpringAnimation(propertyNamed: kPOPLayerPositionX) {
8387
positionAnimation.velocity = 2000

Popping/ViewControllers/CircleViewController.swift

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class CircleViewController: UIViewController
1919
self.addSlider()
2020
}
2121

22+
// MARK: - Private instance methods
23+
2224
private func addCircleView() {
2325
let frame = CGRect(x: 0, y: 0, width: 200, height: 200)
2426
self.circleView = CircleView(frame: frame)

Popping/ViewControllers/ConstraintsViewController.swift

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class ConstraintsViewController: UIViewController
2323
self.updateConstraints(nil)
2424
}
2525

26+
// MARK: - Private instance methods
27+
2628
private func addBarButton() {
2729
let item = UIBarButtonItem(title: "Shuffle", style: .plain, target: self, action: #selector(updateConstraints))
2830
self.navigationItem.rightBarButtonItem = item

Popping/ViewControllers/CustomTransitionViewController.swift

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class CustomTransitionViewController: UIViewController
1616
self.addPresentButton()
1717
}
1818

19+
// MARK: - Private instance methods
20+
1921
private func addPresentButton() {
2022
let presentButton = UIButton(type: .system)
2123
presentButton.translatesAutoresizingMaskIntoConstraints = false
@@ -40,6 +42,8 @@ class CustomTransitionViewController: UIViewController
4042
}
4143
}
4244

45+
// MARK: - Transitioning delegate
46+
4347
extension CustomTransitionViewController: UIViewControllerTransitioningDelegate
4448
{
4549
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {

Popping/ViewControllers/DecayViewController.swift

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class DecayViewController: UIViewController
1919
self.addDragView()
2020
}
2121

22+
// MARK: - Private instance methods
23+
2224
private func addDragView() {
2325
let recognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
2426

@@ -57,6 +59,8 @@ class DecayViewController: UIViewController
5759
}
5860
}
5961

62+
// MARK: - pop Animation delegate
63+
6064
extension DecayViewController: POPAnimationDelegate
6165
{
6266
func pop_animationDidApply(_ anim: POPAnimation!) {

0 commit comments

Comments
 (0)