Skip to content

Commit

Permalink
Hooked up delegate calls & changed DetailViewController lifecycle. (#22)
Browse files Browse the repository at this point in the history
* Hooked up delegate protocol

Added calls to cardWillShowDetailView, cardDidShowDetailView, cardWillCloseDetailView, cardDidCloseDetailView

* Removed duplicate call to cardDidTapInside

* detailView lifecycle changes.

DetailViewController now owns only reference to the detailView. Removed reference to it from Card class.

All DetailViewController setup happens inside of Card.shouldPresent call. Removed setup from Card.cardTapped() call.

Changed how the card.backgroundIV is hooked upto the scrollView in DetailViewController.
  • Loading branch information
amagrude authored and PaoloCuscela committed Nov 15, 2017
1 parent de0765e commit 35412e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
12 changes: 4 additions & 8 deletions Cards/Sources/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ import UIKit
if let content = contentViewController {
self.superVC = superVC
detailVC.addChildViewController(content)
self.detailView = content.view
detailVC.detailView = content.view
detailVC.card = self
detailVC.delegate = self.delegate
}
}
/**
Expand All @@ -119,7 +121,6 @@ import UIKit
//Private Vars
fileprivate var tap = UITapGestureRecognizer()
fileprivate var detailVC = DetailViewController()
fileprivate var detailView: UIView?
var superVC: UIViewController?
var originalFrame = CGRect.zero
var backgroundIV = UIImageView()
Expand All @@ -145,9 +146,6 @@ import UIKit
tap.delegate = self
tap.cancelsTouchesInView = false

if let detail = detailView {
detailVC.detailView = detail
}
detailVC.transitioningDelegate = self

// Adding Subviews
Expand Down Expand Up @@ -189,12 +187,10 @@ import UIKit

//MARK: - Actions

@objc func cardTapped(){
@objc func cardTapped() {
self.delegate?.cardDidTapInside?(card: self)

if let vc = superVC {

detailVC.detailView = detailView
vc.present(self.detailVC, animated: true, completion: nil)
} else {

Expand Down
10 changes: 2 additions & 8 deletions Cards/Sources/CardGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import UIKit
initialize()
}

override func initialize() {
override func initialize() {
super.initialize()

vibrancyV = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: blurEffect)))
Expand Down Expand Up @@ -123,13 +123,7 @@ import UIKit
height: gimme.Y(20))
titleLbl.sizeToFit()
}


override func cardTapped() {
super.cardTapped()
delegate?.cardDidTapInside?(card: self)

}

}


19 changes: 13 additions & 6 deletions Cards/Sources/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ internal class DetailViewController: UIViewController {
var scrollView = UIScrollView()
var originalFrame = CGRect.zero
var snap = UIView()
var card: Card! {
didSet{
scrollView.addSubview(card.backgroundIV)
}
}
var card: Card!
var delegate: CardDelegate?


//MARK: - View Lifecycle
Expand Down Expand Up @@ -46,7 +43,12 @@ internal class DetailViewController: UIViewController {
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
}


override func viewWillAppear(_ animated: Bool) {
scrollView.addSubview(card.backgroundIV)
self.delegate?.cardWillShowDetailView?(card: self.card)
}

override func viewDidAppear(_ animated: Bool) {
self.view.insertSubview(snap, belowSubview: blurView)
originalFrame = scrollView.frame
Expand All @@ -62,12 +64,17 @@ internal class DetailViewController: UIViewController {
scrollView.contentSize = CGSize(width: scrollView.bounds.width, height: detail.frame.maxY)
}

self.delegate?.cardDidShowDetailView?(card: self.card)
}

override func viewWillDisappear(_ animated: Bool) {
self.delegate?.cardWillCloseDetailView?(card: self.card)
snap.removeFromSuperview()
}

override func viewDidDisappear(_ animated: Bool) {
self.delegate?.cardDidCloseDetailView?(card: self.card)
}

//MARK: - Layout & Animations for the content ( rect = Scrollview + card + detail )

Expand Down

0 comments on commit 35412e4

Please sign in to comment.