Skip to content

Commit

Permalink
Added two new mark types.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-mcquilkin-kr committed Oct 10, 2016
1 parent 8b8883c commit 43d19ae
Show file tree
Hide file tree
Showing 24 changed files with 933 additions and 532 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Morph.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
59 changes: 52 additions & 7 deletions M13Checkbox Demo/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 9
return 10
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
Expand Down Expand Up @@ -182,20 +182,47 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove
}
cell.slider?.addTarget(self, action: #selector(DemoViewController.updateAnimationDuration(_:)), for: .valueChanged)
} else if (indexPath as NSIndexPath).item == 4 {
// States cell
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "segmentedControlCell", for: indexPath)
guard let cell = cell as? SegmentedControlCollectionViewCell else {
fatalError()
}
cell.iconView?.image = UIImage(named: "Morph")
cell.titleLabel?.text = "Morphing"
cell.bodyLabel?.text = "The checkbox can either morph between states with marks, or it can animate the old mark out, and the new mark in."
cell.bodyLabel?.sizeToFit()
cell.setNeedsLayout()

cell.segmentedControl?.removeAllSegments()
cell.segmentedControl?.insertSegment(withTitle: "Enabled", at: 0, animated: false)
cell.segmentedControl?.insertSegment(withTitle: "Disabled", at: 1, animated: false)

if checkbox?.enableMorphing == true {
cell.segmentedControl?.selectedSegmentIndex = 0
} else {
cell.segmentedControl?.selectedSegmentIndex = 1
}
cell.segmentedControl?.isEnabled = true

cell.segmentedControl?.addTarget(self, action: #selector(DemoViewController.updateMorphEnabled(_:)), for: .valueChanged)

} else if (indexPath as NSIndexPath).item == 5 {
// States cell
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "segmentedControlCell", for: indexPath)
guard let cell = cell as? SegmentedControlCollectionViewCell else {
fatalError()
}
cell.iconView?.image = UIImage(named: "MarkType")
cell.titleLabel?.text = "Mark Type"
cell.bodyLabel?.text = "The checkbox can double as a radio by switching the mark type to \"Radio\""
cell.bodyLabel?.text = "The checkbox supports several mark combinations, including a radio style checkbox."
cell.bodyLabel?.sizeToFit()
cell.setNeedsLayout()

cell.segmentedControl?.removeAllSegments()
cell.segmentedControl?.insertSegment(withTitle: "Checkmark", at: 0, animated: false)
cell.segmentedControl?.insertSegment(withTitle: "Radio", at: 1, animated: false)
cell.segmentedControl?.insertSegment(withTitle: "+/-", at: 2, animated: false)
cell.segmentedControl?.insertSegment(withTitle: "Disclosure", at: 3, animated: false)

if let state = checkbox?.markType {
switch state {
Expand All @@ -205,13 +232,19 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove
case .radio:
cell.segmentedControl?.selectedSegmentIndex = 1
break
case .addRemove:
cell.segmentedControl?.selectedSegmentIndex = 2
break
case .disclosure:
cell.segmentedControl?.selectedSegmentIndex = 3
break
}
}
cell.segmentedControl?.isEnabled = true

cell.segmentedControl?.addTarget(self, action: #selector(DemoViewController.updateMarkType(_:)), for: .valueChanged)

} else if (indexPath as NSIndexPath).item == 5 {
} else if (indexPath as NSIndexPath).item == 6 {
// States cell
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "segmentedControlCell", for: indexPath)
guard let cell = cell as? SegmentedControlCollectionViewCell else {
Expand Down Expand Up @@ -241,7 +274,7 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove

cell.segmentedControl?.addTarget(self, action: #selector(DemoViewController.updateBoxShape(_:)), for: .valueChanged)

} else if (indexPath as NSIndexPath).item == 6 {
} else if (indexPath as NSIndexPath).item == 7 {
// Animated cell
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sliderCell", for: indexPath)
guard let cell = cell as? SliderCollectionViewCell else {
Expand All @@ -259,7 +292,7 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove
cell.slider?.value = Float(lineWidth)
}
cell.slider?.addTarget(self, action: #selector(DemoViewController.updateMarkLineWidth(_:)), for: .valueChanged)
} else if (indexPath as NSIndexPath).item == 7 {
} else if (indexPath as NSIndexPath).item == 8 {
// Animated cell
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sliderCell", for: indexPath)
guard let cell = cell as? SliderCollectionViewCell else {
Expand All @@ -277,7 +310,7 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove
cell.slider?.value = Float(lineWidth)
}
cell.slider?.addTarget(self, action: #selector(DemoViewController.updateBoxLineWidth(_:)), for: .valueChanged)
} else if (indexPath as NSIndexPath).item == 8 {
} else if (indexPath as NSIndexPath).item == 9 {
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "colorCell", for: indexPath)
guard let cell = cell as? ColorCollectionViewCell else {
fatalError()
Expand Down Expand Up @@ -420,6 +453,14 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove
checkbox?.animationDuration = TimeInterval(sender.value)
}

func updateMorphEnabled(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
checkbox?.enableMorphing = true
} else {
checkbox?.enableMorphing = false
}
}

func updateMarkLineWidth(_ sender: UISlider) {
checkbox?.checkmarkLineWidth = CGFloat(sender.value)
}
Expand All @@ -439,8 +480,12 @@ class DemoViewController: UIViewController, UICollectionViewDataSource, UIPopove
func updateMarkType(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
checkbox?.setMarkType(markType: .checkmark, animated: true)
} else {
} else if sender.selectedSegmentIndex == 1 {
checkbox?.setMarkType(markType: .radio, animated: true)
} else if sender.selectedSegmentIndex == 2 {
checkbox?.setMarkType(markType: .addRemove, animated: true)
} else if sender.selectedSegmentIndex == 3 {
checkbox?.setMarkType(markType: .disclosure, animated: true)
}
}

Expand Down
38 changes: 23 additions & 15 deletions M13Checkbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
objects = {

/* Begin PBXBuildFile section */
43242B4D1DA6BE1B00C6AF91 /* M13CheckboxBounceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1E41CAC66F000ACB4F4 /* M13CheckboxBounceController.swift */; };
43242B4E1DA6BFE400C6AF91 /* M13CheckboxExpandController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1E61CAED49900ACB4F4 /* M13CheckboxExpandController.swift */; };
43242B4F1DA6C11400C6AF91 /* M13CheckboxFlatController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1E81CAED71700ACB4F4 /* M13CheckboxFlatController.swift */; };
43242B501DA6C21100C6AF91 /* M13CheckboxSpiralController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1F71CAEFE7800ACB4F4 /* M13CheckboxSpiralController.swift */; };
43242B511DA6C3EA00C6AF91 /* M13CheckboxFadeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1EF1CAEDD5700ACB4F4 /* M13CheckboxFadeController.swift */; };
43242B521DA6C4D700C6AF91 /* M13CheckboxDotController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1F31CAEFA6300ACB4F4 /* M13CheckboxDotController.swift */; };
43683B141DA689F9001965EB /* M13CheckboxFillController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3591421CAC1F12000FBA3B /* M13CheckboxFillController.swift */; };
43242B551DA7BC1100C6AF91 /* M13CheckboxAddRemovePathGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43242B541DA7BC1100C6AF91 /* M13CheckboxAddRemovePathGenerator.swift */; };
43242B561DA7C2CC00C6AF91 /* M13CheckboxFillController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3591421CAC1F12000FBA3B /* M13CheckboxFillController.swift */; };
43242B571DA7C3CA00C6AF91 /* M13CheckboxBounceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1E41CAC66F000ACB4F4 /* M13CheckboxBounceController.swift */; };
43242B581DA7C4B600C6AF91 /* M13CheckboxExpandController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1E61CAED49900ACB4F4 /* M13CheckboxExpandController.swift */; };
43242B591DA7C57700C6AF91 /* M13CheckboxFlatController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1E81CAED71700ACB4F4 /* M13CheckboxFlatController.swift */; };
43242B5A1DA7C6F400C6AF91 /* M13CheckboxSpiralController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1F71CAEFE7800ACB4F4 /* M13CheckboxSpiralController.swift */; };
43242B5B1DA7C7C300C6AF91 /* M13CheckboxFadeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1EF1CAEDD5700ACB4F4 /* M13CheckboxFadeController.swift */; };
43242B5C1DA7C8A500C6AF91 /* M13CheckboxDotController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA26E1F31CAEFA6300ACB4F4 /* M13CheckboxDotController.swift */; };
434D1FF61DABB52300F5A8C8 /* M13CheckboxDisclosurePathGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 434D1FF51DABB52300F5A8C8 /* M13CheckboxDisclosurePathGenerator.swift */; };
43BDF4E21DA672EA005476B2 /* M13CheckboxCheckPathGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43BDF4E11DA672EA005476B2 /* M13CheckboxCheckPathGenerator.swift */; };
43BDF4E31DA67304005476B2 /* M13CheckboxPathGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43BDF4DE1DA67211005476B2 /* M13CheckboxPathGenerator.swift */; };
43BDF4E51DA6751C005476B2 /* M13CheckboxRadioPathGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43BDF4E41DA6751C005476B2 /* M13CheckboxRadioPathGenerator.swift */; };
Expand Down Expand Up @@ -70,6 +72,8 @@
/* Begin PBXFileReference section */
142C71FD96ACA2685D246CF8 /* Pods_M13Checkbox.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_M13Checkbox.framework; sourceTree = BUILT_PRODUCTS_DIR; };
43242B531DA6D14400C6AF91 /* M13Checkbox.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = M13Checkbox.podspec; sourceTree = "<group>"; };
43242B541DA7BC1100C6AF91 /* M13CheckboxAddRemovePathGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = M13CheckboxAddRemovePathGenerator.swift; path = Sources/Paths/M13CheckboxAddRemovePathGenerator.swift; sourceTree = SOURCE_ROOT; };
434D1FF51DABB52300F5A8C8 /* M13CheckboxDisclosurePathGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = M13CheckboxDisclosurePathGenerator.swift; path = Sources/Paths/M13CheckboxDisclosurePathGenerator.swift; sourceTree = SOURCE_ROOT; };
43A4CE6E1E64F86D23A4560F /* Pods-M13Checkbox.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-M13Checkbox.release.xcconfig"; path = "Pods/Target Support Files/Pods-M13Checkbox/Pods-M13Checkbox.release.xcconfig"; sourceTree = "<group>"; };
43BDF4DE1DA67211005476B2 /* M13CheckboxPathGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = M13CheckboxPathGenerator.swift; path = Sources/Paths/M13CheckboxPathGenerator.swift; sourceTree = SOURCE_ROOT; };
43BDF4E11DA672EA005476B2 /* M13CheckboxCheckPathGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = M13CheckboxCheckPathGenerator.swift; path = Sources/Paths/M13CheckboxCheckPathGenerator.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -171,6 +175,8 @@
43BDF4DE1DA67211005476B2 /* M13CheckboxPathGenerator.swift */,
43BDF4E11DA672EA005476B2 /* M13CheckboxCheckPathGenerator.swift */,
43BDF4E41DA6751C005476B2 /* M13CheckboxRadioPathGenerator.swift */,
43242B541DA7BC1100C6AF91 /* M13CheckboxAddRemovePathGenerator.swift */,
434D1FF51DABB52300F5A8C8 /* M13CheckboxDisclosurePathGenerator.swift */,
);
name = "Path Generators";
sourceTree = "<group>";
Expand Down Expand Up @@ -259,8 +265,8 @@
EA26E1E41CAC66F000ACB4F4 /* M13CheckboxBounceController.swift */,
EA26E1E61CAED49900ACB4F4 /* M13CheckboxExpandController.swift */,
EA26E1E81CAED71700ACB4F4 /* M13CheckboxFlatController.swift */,
EA26E1EF1CAEDD5700ACB4F4 /* M13CheckboxFadeController.swift */,
EA26E1F71CAEFE7800ACB4F4 /* M13CheckboxSpiralController.swift */,
EA26E1EF1CAEDD5700ACB4F4 /* M13CheckboxFadeController.swift */,
EA26E1F31CAEFA6300ACB4F4 /* M13CheckboxDotController.swift */,
);
name = Controllers;
Expand Down Expand Up @@ -448,22 +454,24 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
43242B551DA7BC1100C6AF91 /* M13CheckboxAddRemovePathGenerator.swift in Sources */,
43242B591DA7C57700C6AF91 /* M13CheckboxFlatController.swift in Sources */,
43242B5A1DA7C6F400C6AF91 /* M13CheckboxSpiralController.swift in Sources */,
43BDF4E21DA672EA005476B2 /* M13CheckboxCheckPathGenerator.swift in Sources */,
43242B4F1DA6C11400C6AF91 /* M13CheckboxFlatController.swift in Sources */,
43683B141DA689F9001965EB /* M13CheckboxFillController.swift in Sources */,
43242B581DA7C4B600C6AF91 /* M13CheckboxExpandController.swift in Sources */,
43BDF4E31DA67304005476B2 /* M13CheckboxPathGenerator.swift in Sources */,
43242B5B1DA7C7C300C6AF91 /* M13CheckboxFadeController.swift in Sources */,
EA96F9081CBEB5190066C6B7 /* M13CheckboxController.swift in Sources */,
43242B4E1DA6BFE400C6AF91 /* M13CheckboxExpandController.swift in Sources */,
43242B571DA7C3CA00C6AF91 /* M13CheckboxBounceController.swift in Sources */,
EA96F90E1CBEB5190066C6B7 /* M13CheckboxStrokeController.swift in Sources */,
43242B561DA7C2CC00C6AF91 /* M13CheckboxFillController.swift in Sources */,
43BDF4E51DA6751C005476B2 /* M13CheckboxRadioPathGenerator.swift in Sources */,
434D1FF61DABB52300F5A8C8 /* M13CheckboxDisclosurePathGenerator.swift in Sources */,
EA96F90B1CBEB5190066C6B7 /* M13CheckboxGestureRecognizer.swift in Sources */,
43242B5C1DA7C8A500C6AF91 /* M13CheckboxDotController.swift in Sources */,
EA96F90A1CBEB5190066C6B7 /* M13CheckboxAnimationGenerator.swift in Sources */,
43242B511DA6C3EA00C6AF91 /* M13CheckboxFadeController.swift in Sources */,
EA96F9161CBEB5190066C6B7 /* M13Checkbox+IB.swift in Sources */,
43242B521DA6C4D700C6AF91 /* M13CheckboxDotController.swift in Sources */,
EA96F9071CBEB5190066C6B7 /* M13Checkbox.swift in Sources */,
43242B4D1DA6BE1B00C6AF91 /* M13CheckboxBounceController.swift in Sources */,
43242B501DA6C21100C6AF91 /* M13CheckboxSpiralController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file modified Resources/Fade.pdf
Binary file not shown.
Binary file modified Resources/Icons 2.sketch
Binary file not shown.
Binary file added Resources/Morph.pdf
Binary file not shown.
24 changes: 23 additions & 1 deletion Sources/M13Checkbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public class M13Checkbox: UIControl {
case checkmark = "Checkmark"
/// The mark is a radio style fill.
case radio = "Radio"
/// The mark is an add/remove icon set.
case addRemove = "AddRemove"
/// The mark is a disclosure indicator.
case disclosure = "Disclosure"
}

/**
Expand Down Expand Up @@ -307,7 +311,14 @@ public class M13Checkbox: UIControl {
}

if animated {
controller.animate(checkState, toState: newState)
if enableMorphing {
controller.animate(checkState, toState: newState)
} else {
controller.animate(checkState, toState: nil, completion: { [weak self] in
self?.controller.resetLayersForState(newState)
self?.controller.animate(nil, toState: newState)
})
}
} else {
controller.resetLayersForState(newState)
}
Expand Down Expand Up @@ -368,6 +379,7 @@ public class M13Checkbox: UIControl {
newManager.pathGenerator = controller.pathGenerator
newManager.animationGenerator.animationDuration = controller.animationGenerator.animationDuration
newManager.state = controller.state
newManager.enableMorphing = controller.enableMorphing
newManager.setMarkType(type: controller.markType, animated: false)

// Set up the inital state.
Expand All @@ -382,6 +394,16 @@ public class M13Checkbox: UIControl {
}
}

/// Whether or not to enable morphing between states.
@IBInspectable public var enableMorphing: Bool {
get {
return controller.enableMorphing
}
set {
controller.enableMorphing = newValue
}
}

//----------------------------
// MARK: - UIControl
//----------------------------
Expand Down
6 changes: 3 additions & 3 deletions Sources/M13CheckboxAnimationGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ internal class M13CheckboxAnimationGenerator {
- parameter toPath: The end path.
- returns: A `CABasicAnimation` that animates a path between the `fromPath` and `toPath`.
*/
final func morphAnimation(_ fromPath: UIBezierPath, toPath: UIBezierPath) -> CABasicAnimation {
final func morphAnimation(_ fromPath: UIBezierPath?, toPath: UIBezierPath?) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: "path")
// Set the start and end.
animation.fromValue = fromPath.cgPath
animation.toValue = toPath.cgPath
animation.fromValue = fromPath?.cgPath
animation.toValue = toPath?.cgPath
// Set animation properties.
animation.duration = animationDuration
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
Expand Down
Loading

0 comments on commit 43d19ae

Please sign in to comment.