Skip to content

Commit

Permalink
Update to Swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
PaoloCuscela committed Mar 31, 2019
1 parent bf822df commit b78352c
Show file tree
Hide file tree
Showing 32 changed files with 711 additions and 529 deletions.
6 changes: 3 additions & 3 deletions Cards.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'Cards'
s.version = '1.3.5'
s.summary = 'Awesome iOS 11 appstore cards in swift 4.'
s.version = '1.3.6'
s.summary = 'Awesome iOS 11 appstore cards in swift 5.'
s.homepage = 'https://github.com/PaoloCuscela/Cards'
s.screenshots = 'https://raw.githubusercontent.com/PaoloCuscela/Cards/master/Images/Header.png', 'https://raw.githubusercontent.com/PaoloCuscela/Cards/master/Images/DetailView.gif'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand All @@ -11,5 +11,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '9.0'
s.source_files = 'Cards/Sources/*'
s.frameworks = 'UIKit'
s.dependency 'Player', '0.12.0'
s.dependency 'Player', '0.13.0'
end
2 changes: 1 addition & 1 deletion Cards/Sources/Animator.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Animator: NSObject, UIViewControllerAnimatedTransitioning {

let detailVC = to as! DetailViewController
let bounceOffset = self.bounceTransform(card.originalFrame, to: card.backgroundIV.frame)
container.bringSubview(toFront: detailVC.view)
container.bringSubviewToFront(detailVC.view)
detailVC.card = card

self.card.delegate?.cardIsShowingDetail?(card: self.card)
Expand Down
26 changes: 23 additions & 3 deletions Cards/Sources/Card.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ import UIKit
from -> Your current ViewController (self)
*/
public func shouldPresent( _ contentViewController: UIViewController?, from superVC: UIViewController?, fullscreen: Bool = false) {
if let content = contentViewController {
if detailVC.children.count > 0{
let viewControllers:[UIViewController] = detailVC.children
for viewContoller in viewControllers{
viewContoller.willMove(toParent: nil)
viewContoller.view.removeFromSuperview()
viewContoller.removeFromParent()
}
}
detailVC.isViewAdded = false
if let content = contentViewController{
self.superVC = superVC
detailVC.addChildViewController(content)
detailVC.addChild(content)
detailVC.detailView = content.view
detailVC.card = self
detailVC.delegate = self.delegate
Expand All @@ -125,7 +134,7 @@ import UIKit

//Private Vars
fileprivate var tap = UITapGestureRecognizer()
fileprivate var detailVC = DetailViewController()
var detailVC = DetailViewController()
weak var superVC: UIViewController?
var originalFrame = CGRect.zero
public var backgroundIV = UIImageView()
Expand Down Expand Up @@ -184,6 +193,17 @@ import UIKit
contentInset = 6
}

/**
Opens the card if detail view is set.
*/
open func open(){
if let superview = self.superview {
originalFrame = superview.convert(self.frame, to: nil)
log("CARD: open() called, setting original frame to ---> \(originalFrame)" )
}
shrinkAnimated()
self.cardTapped()
}

//MARK: - Layout

Expand Down
Empty file modified Cards/Sources/CardArticle.swift
100644 → 100755
Empty file.
Empty file modified Cards/Sources/CardGroup.swift
100644 → 100755
Empty file.
Empty file modified Cards/Sources/CardGroupSliding.swift
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions Cards/Sources/CardHighlight.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ import UIKit
titleLbl.minimumScaleFactor = 0.1
titleLbl.lineBreakMode = .byTruncatingTail
titleLbl.numberOfLines = 3
backgroundIV.bringSubview(toFront: titleLbl)
backgroundIV.bringSubviewToFront(titleLbl)

itemTitleLbl.textColor = textColor
itemTitleLbl.text = itemTitle
Expand All @@ -156,7 +156,7 @@ import UIKit
actionBtn.layer.backgroundColor = lightColor.cgColor
actionBtn.clipsToBounds = true
if self.buttonText != nil {
let btnTitle = NSAttributedString(string: buttonText!.uppercased(), attributes: [ NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16, weight: .black), NSAttributedString.Key.foregroundColor : self.tintColor])
let btnTitle = NSAttributedString(string: buttonText!.uppercased(), attributes: [ NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16, weight: .black), NSAttributedString.Key.foregroundColor : self.tintColor ?? UIColor.black])
actionBtn.setAttributedTitle(btnTitle, for: .normal)
btnWidth = CGFloat((buttonText!.count + 2) * 10)
}
Expand Down
9 changes: 7 additions & 2 deletions Cards/Sources/CardPlayer.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import Player
Required. View controller that should display the player.
*/
public func shouldDisplayPlayer( from vc: UIViewController ) {
vc.addChildViewController(player)
vc.addChild(player)
}

private var player = Player() // Player provided by Patrik Piemonte
Expand Down Expand Up @@ -130,7 +130,7 @@ import Player

backgroundIV.addSubview(self.player.view)
playPauseV.contentView.addSubview(playIV)
playPauseV.contentView.bringSubview(toFront: playIV)
playPauseV.contentView.bringSubviewToFront(playIV)

// Gestures
player.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(playerTapped)))
Expand Down Expand Up @@ -204,8 +204,13 @@ import Player
let move = ( aspect1016 - aspect921 ) * 2

subtitleLbl.transform = isPresenting ? CGAffineTransform(translationX: 0, y: move) : CGAffineTransform.identity
let currentHeight = backgroundIV.frame.size.height
backgroundIV.frame.size.height = originalFrame.height + ( isPresenting ? move/2 : 0 )

if backgroundIV.frame.size.height <= 0 {
backgroundIV.frame.size.height = currentHeight
}

player.view.frame.origin = CGPoint.zero
player.view.frame.size = CGSize(width: backgroundIV.bounds.width, height: isPresenting ? aspect1016 : aspect921 )
playerCoverIV.frame = player.view.bounds
Expand Down
40 changes: 30 additions & 10 deletions Cards/Sources/DetailViewController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import UIKit
internal class DetailViewController: UIViewController {

var blurView = UIVisualEffectView(effect: UIBlurEffect(style: .extraLight ))
weak var detailView: UIView?
var detailView: UIView?
var scrollView = UIScrollView()
var snap = UIView()
weak var card: Card!
var card: Card!
weak var delegate: CardDelegate?
var isFullscreen = false {
didSet { scrollViewOriginalYPosition = isFullscreen ? 0 : 40 }
Expand All @@ -27,17 +27,21 @@ internal class DetailViewController: UIViewController {
if isFullscreen { return true }
else { return false }
}
var isViewAdded = false

//MARK: - View Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
card.log("DetailVC: Loaded")

self.setupView()
}

func setupView() {
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
}

}
self.snap = UIScreen.main.snapshotView(afterScreenUpdates: true)
self.view.addSubview(blurView)
self.view.addSubview(scrollView)
Expand All @@ -63,17 +67,20 @@ internal class DetailViewController: UIViewController {
blurView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissVC)))
xButton.isUserInteractionEnabled = true
view.isUserInteractionEnabled = true

isViewAdded = true
}


override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isViewAdded == false {
self.setupView()
}
scrollView.addSubview(card.backgroundIV)
self.delegate?.cardWillShowDetailView?(card: self.card)
}

override func viewDidAppear(_ animated: Bool) {

super.viewDidAppear(animated)
//originalFrame = scrollView.frame

if isFullscreen {
Expand Down Expand Up @@ -108,10 +115,12 @@ internal class DetailViewController: UIViewController {
detailView?.alpha = 0
snap.removeFromSuperview()
xButton.removeFromSuperview()
super.viewWillDisappear(animated)
}

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


Expand Down Expand Up @@ -140,7 +149,7 @@ internal class DetailViewController: UIViewController {

// Layout for present in non-fullscreen
} else {
scrollView.frame.size = CGSize(width: LayoutHelper.YScreen(90), height: LayoutHelper.XScreen(100) - 20)
scrollView.frame.size = CGSize(width: LayoutHelper.XScreen(90), height: LayoutHelper.YScreen(100) - 20)
scrollView.center = blurView.center
scrollView.frame.origin.y = 40
}
Expand Down Expand Up @@ -185,7 +194,6 @@ extension DetailViewController: UIScrollViewDelegate {
scrollView.frame.origin.y -= y/2
}

guard offset < 60 else { dismissVC(); return }
card.delegate?.cardDetailIsScrolling?(card: card)
}

Expand All @@ -211,6 +219,18 @@ extension DetailViewController: UIScrollViewDelegate {
})
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {

let offset = scrollView.frame.origin.y - scrollViewOriginalYPosition
guard offset > 0 else { return }

// Come back after pull animation
UIView.animate(withDuration: 0.1, animations: {
scrollView.frame.origin.y = self.scrollViewOriginalYPosition
self.scrollView.contentOffset.y = 0
})
}

}

class XButton: UIButton {
Expand Down
10 changes: 2 additions & 8 deletions Cards/Sources/LayoutHelper.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,11 @@ open class LayoutHelper {
}

static public func XScreen(_ percentage: CGFloat) -> CGFloat {


return percentage * UIScreen.main.bounds.height / 100

return percentage * UIScreen.main.bounds.width / 100
}

static public func YScreen(_ percentage: CGFloat) -> CGFloat {


return percentage * UIScreen.main.bounds.width / 100

return percentage * UIScreen.main.bounds.height / 100
}

}
Expand Down
27 changes: 6 additions & 21 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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>"; };
6D3CD3321F9BD40B00C0592C /* Cards.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Cards.podspec; path = ../Cards.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
6D3CD3411F9BDE0D00C0592C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
6D436D531F9BD34600B05FA6 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
6D436D561F9BD34600B05FA6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -133,7 +133,6 @@
6D436D501F9BD34600B05FA6 /* Frameworks */,
6D436D511F9BD34600B05FA6 /* Resources */,
F00B028E32056EAAB78B17B6 /* [CP] Embed Pods Frameworks */,
1F4F32B159D4D16417DBCB18 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -156,6 +155,7 @@
TargetAttributes = {
6D436D521F9BD34600B05FA6 = {
CreatedOnToolsVersion = 9.0.1;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -192,21 +192,6 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
1F4F32B159D4D16417DBCB18 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Demo/Pods-Demo-resources.sh\"\n";
showEnvVarsInLog = 0;
};
93015ADBE87A8D2AB5D07F95 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -402,10 +387,10 @@
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = it.paolocuscela.Cards;
PRODUCT_BUNDLE_IDENTIFIER = it.paolocuscela.Cardz;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -421,10 +406,10 @@
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = it.paolocuscela.Cards;
PRODUCT_BUNDLE_IDENTIFIER = it.paolocuscela.Cardz;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

Expand Down
Loading

0 comments on commit b78352c

Please sign in to comment.