Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
Fixed a bug preventing the detail view controller to manage its view inside the card.
  • Loading branch information
PaoloCuscela committed Nov 3, 2017
1 parent e2f88d1 commit e98350b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 20 deletions.
14 changes: 9 additions & 5 deletions Cards/Sources/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import UIKit
}

@IBDesignable open class Card: UIView, CardDelegate {

// Storyboard Inspectable vars
/**
Color for the card's labels.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
6D0C91581FA8BF350073554B /* ArticleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleViewController.swift; sourceTree = "<group>"; };
6D1F24511FACC2E6002E41FF /* CardContentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardContentViewController.swift; sourceTree = "<group>"; };
6D37D92B1FA8852C00B33EA0 /* GroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupViewController.swift; sourceTree = "<group>"; };
6D3CD3321F9BD40B00C0592C /* Cards.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Cards.podspec; path = ../Cards.podspec; sourceTree = "<group>"; };
6D3CD3411F9BDE0D00C0592C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -85,6 +87,7 @@
6D965BA71FA7B6DD00705AAA /* PlayerViewController.swift */,
6D37D92B1FA8852C00B33EA0 /* GroupViewController.swift */,
6D0C91581FA8BF350073554B /* ArticleViewController.swift */,
6D1F24511FACC2E6002E41FF /* CardContentViewController.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand Down
22 changes: 15 additions & 7 deletions Demo/Demo/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="VB5-vT-PKk">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="VB5-vT-PKk">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -193,12 +193,12 @@
</objects>
<point key="canvasLocation" x="-3985" y="-129"/>
</scene>
<!--View Controller-->
<!--Card Content View Controller-->
<scene sceneID="Pec-lw-cdD">
<objects>
<viewController storyboardIdentifier="CardContent" useStoryboardIdentifierAsRestorationIdentifier="YES" id="E9y-vp-odE" sceneMemberID="viewController">
<viewController storyboardIdentifier="CardContent" useStoryboardIdentifierAsRestorationIdentifier="YES" id="E9y-vp-odE" customClass="CardContentViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" autoresizesSubviews="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" id="tif-Mz-Tb0">
<rect key="frame" x="0.0" y="0.0" width="325" height="470"/>
<rect key="frame" x="0.0" y="0.0" width="325" height="500"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Welcome to Demo !!" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cpR-bQ-f5O">
Expand Down Expand Up @@ -227,17 +227,25 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Utd-w6-9A3">
<rect key="frame" x="84" y="465" width="157" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Do some magic ✨✨ "/>
<connections>
<action selector="doMagic:" destination="E9y-vp-odE" eventType="touchUpInside" id="56l-Dz-k92"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.92143100499999997" green="0.92145264149999995" blue="0.92144101860000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6gC-dO-B8i"/>
</view>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<size key="freeformSize" width="325" height="470"/>
<size key="freeformSize" width="325" height="500"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="eJ9-HG-hE3" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-5140" y="-474"/>
<point key="canvasLocation" x="-5223" y="-584"/>
</scene>
</scenes>
<resources>
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/ViewControllers/ArticleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
37 changes: 37 additions & 0 deletions Demo/Demo/ViewControllers/CardContentViewController.swift
Original file line number Diff line number Diff line change
@@ -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)))]


}

}
4 changes: 2 additions & 2 deletions Demo/Demo/ViewControllers/GroupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
12 changes: 9 additions & 3 deletions Demo/Demo/ViewControllers/HighlightViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}


Expand All @@ -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 :)")
}
Expand All @@ -62,3 +65,6 @@ extension HighlightViewController: CardDelegate {
}

}



2 changes: 1 addition & 1 deletion Demo/Demo/ViewControllers/PlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down

0 comments on commit e98350b

Please sign in to comment.