diff --git a/Cards/Sources/Card.swift b/Cards/Sources/Card.swift index e850c96..f7810ba 100644 --- a/Cards/Sources/Card.swift +++ b/Cards/Sources/Card.swift @@ -28,7 +28,7 @@ import UIKit } @IBDesignable open class Card: UIView, CardDelegate { - + // Storyboard Inspectable vars /** Color for the card's labels. @@ -92,11 +92,15 @@ import UIKit } } /** - detailView -> The view to show after presenting detail; from -> Your current ViewController (self) + contentViewController -> The view controller to present when the card is tapped + from -> Your current ViewController (self) */ - public func shouldPresent( _ detailView: UIView? = nil, from superVC: UIViewController? = nil) { - self.superVC = superVC - self.detailView = detailView + public func shouldPresent( _ contentViewController: UIViewController? = nil, from superVC: UIViewController? = nil) { + if let content = contentViewController { + self.superVC = superVC + detailVC.addChildViewController(content) + self.detailView = content.view + } } /** If the card should display parallax effect. diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index 645fc6c..2719c98 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 6D0C91591FA8BF350073554B /* ArticleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0C91581FA8BF350073554B /* ArticleViewController.swift */; }; + 6D1F24521FACC2E6002E41FF /* CardContentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D1F24511FACC2E6002E41FF /* CardContentViewController.swift */; }; 6D37D92C1FA8852C00B33EA0 /* GroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D37D92B1FA8852C00B33EA0 /* GroupViewController.swift */; }; 6D3CD3421F9BDE0D00C0592C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6D3CD3411F9BDE0D00C0592C /* Assets.xcassets */; }; 6D436D571F9BD34600B05FA6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D436D561F9BD34600B05FA6 /* AppDelegate.swift */; }; @@ -21,6 +22,7 @@ /* Begin PBXFileReference section */ 38CFFDBE6D3C33B1A464184C /* Pods-Demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"; sourceTree = ""; }; 6D0C91581FA8BF350073554B /* ArticleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleViewController.swift; sourceTree = ""; }; + 6D1F24511FACC2E6002E41FF /* CardContentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardContentViewController.swift; sourceTree = ""; }; 6D37D92B1FA8852C00B33EA0 /* GroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupViewController.swift; sourceTree = ""; }; 6D3CD3321F9BD40B00C0592C /* Cards.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Cards.podspec; path = ../Cards.podspec; sourceTree = ""; }; 6D3CD3411F9BDE0D00C0592C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -85,6 +87,7 @@ 6D965BA71FA7B6DD00705AAA /* PlayerViewController.swift */, 6D37D92B1FA8852C00B33EA0 /* GroupViewController.swift */, 6D0C91581FA8BF350073554B /* ArticleViewController.swift */, + 6D1F24511FACC2E6002E41FF /* CardContentViewController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -249,6 +252,7 @@ 6D37D92C1FA8852C00B33EA0 /* GroupViewController.swift in Sources */, 6D436D571F9BD34600B05FA6 /* AppDelegate.swift in Sources */, 6D0C91591FA8BF350073554B /* ArticleViewController.swift in Sources */, + 6D1F24521FACC2E6002E41FF /* CardContentViewController.swift in Sources */, 6D965BA41FA79A6300705AAA /* HighlightViewController.swift in Sources */, 6D965BA81FA7B6DD00705AAA /* PlayerViewController.swift in Sources */, ); diff --git a/Demo/Demo/Storyboards/Base.lproj/Main.storyboard b/Demo/Demo/Storyboards/Base.lproj/Main.storyboard index 12d42fe..6e2343b 100755 --- a/Demo/Demo/Storyboards/Base.lproj/Main.storyboard +++ b/Demo/Demo/Storyboards/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -193,12 +193,12 @@ - + - + - + + - + - + diff --git a/Demo/Demo/ViewControllers/ArticleViewController.swift b/Demo/Demo/ViewControllers/ArticleViewController.swift index 2278257..7063696 100644 --- a/Demo/Demo/ViewControllers/ArticleViewController.swift +++ b/Demo/Demo/ViewControllers/ArticleViewController.swift @@ -16,7 +16,7 @@ class ArticleViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - let cardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent").view + let cardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent") card.shouldPresent(cardContent, from: self) diff --git a/Demo/Demo/ViewControllers/CardContentViewController.swift b/Demo/Demo/ViewControllers/CardContentViewController.swift new file mode 100644 index 0000000..9e02a78 --- /dev/null +++ b/Demo/Demo/ViewControllers/CardContentViewController.swift @@ -0,0 +1,37 @@ +// +// DetailViewController.swift +// Demo +// +// Created by Paolo Cuscela on 03/11/17. +// Copyright © 2017 Paolo Cuscela. All rights reserved. +// + +import UIKit + +class CardContentViewController: UIViewController { + + + let colors = [ + + UIColor.red, + UIColor.yellow, + UIColor.blue, + UIColor.green, + UIColor.brown, + UIColor.purple, + UIColor.orange + + ] + + override func viewDidLoad() { + print("Loaded!") + } + + @IBAction func doMagic(_ sender: Any) { + + view.backgroundColor = colors[Int(arc4random_uniform(UInt32(colors.count)))] + + + } + +} diff --git a/Demo/Demo/ViewControllers/GroupViewController.swift b/Demo/Demo/ViewControllers/GroupViewController.swift index ba0d784..52322fc 100644 --- a/Demo/Demo/ViewControllers/GroupViewController.swift +++ b/Demo/Demo/ViewControllers/GroupViewController.swift @@ -30,10 +30,10 @@ class GroupViewController: UIViewController { sliding.icons = icons - let groupCardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent").view + let groupCardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent") group.shouldPresent(groupCardContent, from: self) - let slidingCardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent").view + let slidingCardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent") sliding.shouldPresent(slidingCardContent, from: self) diff --git a/Demo/Demo/ViewControllers/HighlightViewController.swift b/Demo/Demo/ViewControllers/HighlightViewController.swift index 8dc3db1..52b1287 100644 --- a/Demo/Demo/ViewControllers/HighlightViewController.swift +++ b/Demo/Demo/ViewControllers/HighlightViewController.swift @@ -35,13 +35,15 @@ class HighlightViewController: UIViewController { first.hasParallax = true second.delegate = self - let cardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent").view + let cardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent") second.shouldPresent(cardContent, from: self) } - + func random(min: Int, max:Int) -> Int { + return min + Int(arc4random_uniform(UInt32(max - min + 1))) + } } @@ -50,7 +52,8 @@ extension HighlightViewController: CardDelegate { func cardDidTapInside(card: Card) { if card == first { - card.shadowColor = colors[Int(arc4random_uniform(UInt32(colors.count)))] + card.shadowColor = colors[random(min: 0, max: colors.count-1)] + (card as! CardHighlight).title = "everyday \nI'm \nshufflin'" } else { print("Hey, I'm the second one :)") } @@ -62,3 +65,6 @@ extension HighlightViewController: CardDelegate { } } + + + diff --git a/Demo/Demo/ViewControllers/PlayerViewController.swift b/Demo/Demo/ViewControllers/PlayerViewController.swift index 1f65d82..4b3c0ba 100644 --- a/Demo/Demo/ViewControllers/PlayerViewController.swift +++ b/Demo/Demo/ViewControllers/PlayerViewController.swift @@ -29,7 +29,7 @@ class PlayerViewController: UIViewController { card.subtitle = "Inside the extraordinary world of Buck Bunny" card.category = "today's movie" - let cardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent").view + let cardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent") card.shouldPresent(cardContent, from: self) } diff --git a/README.md b/README.md index 4d5d9e6..4894ab5 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ card.textColor = UIColor.white card.hasParallax = true let cardContentVC = storyboard!.instantiateViewController(withIdentifier: "CardContent") -card.shouldPresent(cardContentVC.view, from: self) +card.shouldPresent(cardContentVC, from: self) view.addSubview(card) ```