diff --git a/Cards.podspec b/Cards.podspec index d88c0f3..026ca33 100644 --- a/Cards.podspec +++ b/Cards.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Cards' - s.version = '1.2.6' + s.version = '1.3.0' s.summary = 'Awesome iOS 11 appstore cards in swift 4.' s.homepage = 'https://github.com/PaoloCuscela/Cards' s.screenshots = 'https://raw.githubusercontent.com/PaoloCuscela/Cards/master/Images/Overview.png', 'https://raw.githubusercontent.com/PaoloCuscela/Cards/master/Images/CardGroupSliding.gif' diff --git a/Cards/Sources/Animator.swift b/Cards/Sources/Animator.swift index 44bdeec..392b3fd 100644 --- a/Cards/Sources/Animator.swift +++ b/Cards/Sources/Animator.swift @@ -36,7 +36,6 @@ class Animator: NSObject, UIViewControllerAnimatedTransitioning { // Detail View Controller Dismiss Animations card.isPresenting = false - let superVC = to let detailVC = from as! DetailViewController let cardBackgroundFrame = detailVC.scrollView.convert(card.backgroundIV.frame, to: nil) let bounce = self.bounceTransform(cardBackgroundFrame, to: card.originalFrame) diff --git a/Cards/Sources/Card.swift b/Cards/Sources/Card.swift index 1d7a15d..2a430e0 100644 --- a/Cards/Sources/Card.swift +++ b/Cards/Sources/Card.swift @@ -95,13 +95,14 @@ import UIKit contentViewController -> The view controller to present when the card is tapped from -> Your current ViewController (self) */ - public func shouldPresent( _ contentViewController: UIViewController? = nil, from superVC: UIViewController? = nil) { + public func shouldPresent( _ contentViewController: UIViewController?, from superVC: UIViewController?, fullscreen: Bool = false) { if let content = contentViewController { self.superVC = superVC detailVC.addChildViewController(content) detailVC.detailView = content.view detailVC.card = self detailVC.delegate = self.delegate + detailVC.isFullscreen = fullscreen } } /** diff --git a/Cards/Sources/CardHighlight.swift b/Cards/Sources/CardHighlight.swift index 30979cd..fb5d607 100644 --- a/Cards/Sources/CardHighlight.swift +++ b/Cards/Sources/CardHighlight.swift @@ -156,7 +156,7 @@ import UIKit let btnTitle = NSAttributedString(string: buttonText.uppercased(), attributes: [ NSAttributedStringKey.font : UIFont.systemFont(ofSize: 16, weight: .black), NSAttributedStringKey.foregroundColor : self.tintColor]) actionBtn.setAttributedTitle(btnTitle, for: .normal) - btnWidth = CGFloat((buttonText.characters.count + 2) * 10) + btnWidth = CGFloat((buttonText.count + 2) * 10) layout() diff --git a/Cards/Sources/DetailViewController.swift b/Cards/Sources/DetailViewController.swift index 4a077ec..51d9709 100644 --- a/Cards/Sources/DetailViewController.swift +++ b/Cards/Sources/DetailViewController.swift @@ -16,7 +16,9 @@ internal class DetailViewController: UIViewController { var snap = UIView() var card: Card! var delegate: CardDelegate? + var isFullscreen = false + fileprivate var xButton = XButton() //MARK: - View Lifecycle @@ -26,23 +28,31 @@ internal class DetailViewController: UIViewController { self.snap = UIScreen.main.snapshotView(afterScreenUpdates: true) self.view.addSubview(blurView) self.view.addSubview(scrollView) + if let detail = detailView { scrollView.addSubview(detail) - detail.autoresizingMask = .flexibleWidth detail.alpha = 0 + detail.autoresizingMask = .flexibleWidth } blurView.frame = self.view.bounds scrollView.layer.backgroundColor = detailView?.backgroundColor?.cgColor ?? UIColor.white.cgColor - scrollView.layer.cornerRadius = 20 + scrollView.layer.cornerRadius = isFullscreen ? 0 : 20 scrollView.delegate = self scrollView.alwaysBounceVertical = true scrollView.showsVerticalScrollIndicator = false scrollView.showsHorizontalScrollIndicator = false + + xButton.addTarget(self, action: #selector(dismissVC), for: .touchUpInside) + blurView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissVC))) + xButton.isUserInteractionEnabled = true + view.isUserInteractionEnabled = true + } + override func viewWillAppear(_ animated: Bool) { scrollView.addSubview(card.backgroundIV) @@ -50,9 +60,15 @@ internal class DetailViewController: UIViewController { } override func viewDidAppear(_ animated: Bool) { - self.view.insertSubview(snap, belowSubview: blurView) + originalFrame = scrollView.frame + if isFullscreen { + view.addSubview(xButton) + } + + view.insertSubview(snap, belowSubview: blurView) + if let detail = detailView { detail.alpha = 1 @@ -62,6 +78,15 @@ internal class DetailViewController: UIViewController { height: detail.frame.height) scrollView.contentSize = CGSize(width: scrollView.bounds.width, height: detail.frame.maxY) + + + xButton.frame = CGRect (x: scrollView.frame.maxX - 20 - 40, + y: scrollView.frame.minY + 20, + width: 40, + height: 40) + + + } self.delegate?.cardDidShowDetailView?(card: self.card) @@ -69,13 +94,16 @@ internal class DetailViewController: UIViewController { override func viewWillDisappear(_ animated: Bool) { self.delegate?.cardWillCloseDetailView?(card: self.card) + detailView?.alpha = 0 snap.removeFromSuperview() + xButton.removeFromSuperview() } override func viewDidDisappear(_ animated: Bool) { self.delegate?.cardDidCloseDetailView?(card: self.card) } + //MARK: - Layout & Animations for the content ( rect = Scrollview + card + detail ) func layout(_ rect: CGRect, isPresenting: Bool, isAnimating: Bool = true, transform: CGAffineTransform = CGAffineTransform.identity){ @@ -88,9 +116,15 @@ internal class DetailViewController: UIViewController { return } - scrollView.frame.size = CGSize(width: LayoutHelper.XScreen(85), height: LayoutHelper.YScreen(100) - 20) - scrollView.center = blurView.center - scrollView.frame.origin.y = 40 + if isFullscreen { + scrollView.frame = view.frame + + } else { + scrollView.frame.size = CGSize(width: LayoutHelper.XScreen(85), height: LayoutHelper.YScreen(100) - 20) + scrollView.center = blurView.center + scrollView.frame.origin.y = 40 + } + scrollView.frame = scrollView.frame.applying(transform) card.backgroundIV.frame.origin = scrollView.bounds.origin @@ -99,6 +133,14 @@ internal class DetailViewController: UIViewController { card.layout(animating: isAnimating) } + + + //MARK: - Actions + + @objc func dismissVC(){ + scrollView.contentOffset.y = 0 + dismiss(animated: true, completion: nil) + } } @@ -112,8 +154,11 @@ extension DetailViewController: UIScrollViewDelegate { let origin = originalFrame.origin.y let currentOrigin = originalFrame.origin.y + xButton.alpha = y - (card.backgroundIV.bounds.height * 0.6) + if (y<0 || currentOrigin > origin) { scrollView.frame.origin.y -= y/2 + scrollView.contentOffset.y = 0 } @@ -145,4 +190,61 @@ extension DetailViewController: UIScrollViewDelegate { } +class XButton: UIButton { + + private let circle = UIVisualEffectView(effect: UIBlurEffect(style: .dark)) + + override var frame: CGRect { + didSet{ + setNeedsDisplay() + } + } + + override init(frame: CGRect) { + super.init(frame: frame) + self.addSubview(circle) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + override func draw(_ rect: CGRect) { + super.draw(rect) + + let xPath = UIBezierPath() + let xLayer = CAShapeLayer() + let inset = rect.width * 0.3 + + xPath.move(to: CGPoint(x: inset, y: inset)) + xPath.addLine(to: CGPoint(x: rect.maxX - inset, y: rect.maxY - inset)) + + xPath.move(to: CGPoint(x: rect.maxX - inset, y: inset)) + xPath.addLine(to: CGPoint(x: inset, y: rect.maxY - inset)) + + xLayer.path = xPath.cgPath + + xLayer.strokeColor = UIColor.white.cgColor + xLayer.lineWidth = 2.0 + self.layer.addSublayer(xLayer) + + circle.frame = rect + circle.layer.cornerRadius = circle.bounds.width / 2 + circle.clipsToBounds = true + circle.isUserInteractionEnabled = false + + + } + + +} + + + + + + + + + diff --git a/Demo/Demo.xcworkspace/xcuserdata/paolocuscela.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Demo/Demo.xcworkspace/xcuserdata/paolocuscela.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 7f77e06..b4ce7c7 100644 --- a/Demo/Demo.xcworkspace/xcuserdata/paolocuscela.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Demo/Demo.xcworkspace/xcuserdata/paolocuscela.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -90,11 +90,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/Card.swift" - timestampString = "531153197.905523" + timestampString = "532807255.096243" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "148" - endingLineNumber = "148" + startingLineNumber = "149" + endingLineNumber = "149" landmarkName = "initialize()" landmarkType = "7"> @@ -186,11 +186,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/Card.swift" - timestampString = "531153197.905664" + timestampString = "532807255.096943" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "186" - endingLineNumber = "186" + startingLineNumber = "187" + endingLineNumber = "187" landmarkName = "Card" landmarkType = "3"> @@ -234,11 +234,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/Card.swift" - timestampString = "531153197.905728" + timestampString = "532807255.097475" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "185" - endingLineNumber = "185" + startingLineNumber = "186" + endingLineNumber = "186" landmarkName = "Card" landmarkType = "3"> @@ -378,11 +378,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/Card.swift" - timestampString = "531153197.905836" + timestampString = "532807255.097918" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "191" - endingLineNumber = "191" + startingLineNumber = "192" + endingLineNumber = "192" landmarkName = "cardTapped()" landmarkType = "7"> @@ -490,11 +490,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/Card.swift" - timestampString = "531153197.905943" + timestampString = "532807255.098325" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "244" - endingLineNumber = "244" + startingLineNumber = "245" + endingLineNumber = "245" landmarkName = "Card" landmarkType = "21"> @@ -584,12 +584,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/CardPlayer.swift" - timestampString = "531153197.90603" + timestampString = "532808003.518268" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "252" endingLineNumber = "252" - landmarkName = "touchesBegan(_:with:)" + landmarkName = "pause()" landmarkType = "7"> @@ -600,13 +600,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Demo/ViewControllers/HighlightViewController.swift" - timestampString = "531086224.429599" + timestampString = "532807255.098897" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "61" endingLineNumber = "61" - landmarkName = "cardHighlightDidTapButton(card:button:)" - landmarkType = "7"> + landmarkName = "HighlightViewController" + landmarkType = "21"> @@ -632,12 +632,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/CardHighlight.swift" - timestampString = "531139323.422017" + timestampString = "532808125.257844" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "145" endingLineNumber = "145" - landmarkName = "layout(animating:)" + landmarkName = "draw(_:)" landmarkType = "7"> @@ -648,7 +648,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Demo/ViewControllers/HighlightViewController.swift" - timestampString = "531086224.430104" + timestampString = "532807255.099049" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "55" @@ -664,13 +664,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Demo/ViewControllers/HighlightViewController.swift" - timestampString = "531086224.430204" + timestampString = "532807255.09914" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "51" endingLineNumber = "51" - landmarkName = "cardDidTapInside(card:)" - landmarkType = "7"> + landmarkName = "HighlightViewController" + landmarkType = "21"> @@ -696,12 +696,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/CardPlayer.swift" - timestampString = "531153197.906273" + timestampString = "532808003.518504" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "121" endingLineNumber = "121" - landmarkName = "draw(_:)" + landmarkName = "initialize()" landmarkType = "7"> @@ -728,14 +728,78 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "../Cards/Sources/Animator.swift" - timestampString = "531153197.906397" + timestampString = "532808125.258354" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "94" - endingLineNumber = "94" + startingLineNumber = "93" + endingLineNumber = "93" landmarkName = "animateTransition(using:)" landmarkType = "7"> + + + + + + + + + + + + + + + + diff --git a/Demo/Demo/Storyboards/Base.lproj/Main.storyboard b/Demo/Demo/Storyboards/Base.lproj/Main.storyboard index 6e2343b..6f7d4d1 100755 --- a/Demo/Demo/Storyboards/Base.lproj/Main.storyboard +++ b/Demo/Demo/Storyboards/Base.lproj/Main.storyboard @@ -1,11 +1,12 @@ - + + @@ -15,7 +16,7 @@ - + @@ -62,7 +63,7 @@ - + @@ -96,7 +97,7 @@ - + @@ -129,7 +130,7 @@ - + @@ -198,54 +199,80 @@ - + - - - + + + + + + + + + + + + + + + + + + - - + diff --git a/Demo/Demo/ViewControllers/HighlightViewController.swift b/Demo/Demo/ViewControllers/HighlightViewController.swift index 52b1287..1c1990c 100644 --- a/Demo/Demo/ViewControllers/HighlightViewController.swift +++ b/Demo/Demo/ViewControllers/HighlightViewController.swift @@ -36,7 +36,7 @@ class HighlightViewController: UIViewController { second.delegate = self let cardContent = storyboard?.instantiateViewController(withIdentifier: "CardContent") - second.shouldPresent(cardContent, from: self) + second.shouldPresent(cardContent, from: self, fullscreen: true) } diff --git a/README.md b/README.md index 08fb00c..3a40722 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, from: self) +card.shouldPresent(cardContentVC, from: self, fullscreen: false) view.addSubview(card) ```