diff --git a/Cards.podspec b/Cards.podspec index 24790f9..98d852a 100644 --- a/Cards.podspec +++ b/Cards.podspec @@ -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' } @@ -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 diff --git a/Cards/Sources/Animator.swift b/Cards/Sources/Animator.swift old mode 100644 new mode 100755 index 07b2c7a..2d22e4c --- a/Cards/Sources/Animator.swift +++ b/Cards/Sources/Animator.swift @@ -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) diff --git a/Cards/Sources/Card.swift b/Cards/Sources/Card.swift old mode 100644 new mode 100755 index dc9c545..7eb5f9e --- a/Cards/Sources/Card.swift +++ b/Cards/Sources/Card.swift @@ -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 @@ -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() @@ -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 diff --git a/Cards/Sources/CardArticle.swift b/Cards/Sources/CardArticle.swift old mode 100644 new mode 100755 diff --git a/Cards/Sources/CardGroup.swift b/Cards/Sources/CardGroup.swift old mode 100644 new mode 100755 diff --git a/Cards/Sources/CardGroupSliding.swift b/Cards/Sources/CardGroupSliding.swift old mode 100644 new mode 100755 diff --git a/Cards/Sources/CardHighlight.swift b/Cards/Sources/CardHighlight.swift old mode 100644 new mode 100755 index dca1430..3ff64a0 --- a/Cards/Sources/CardHighlight.swift +++ b/Cards/Sources/CardHighlight.swift @@ -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 @@ -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) } diff --git a/Cards/Sources/CardPlayer.swift b/Cards/Sources/CardPlayer.swift old mode 100644 new mode 100755 index 9dd5317..a909714 --- a/Cards/Sources/CardPlayer.swift +++ b/Cards/Sources/CardPlayer.swift @@ -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 @@ -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))) @@ -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 diff --git a/Cards/Sources/DetailViewController.swift b/Cards/Sources/DetailViewController.swift old mode 100644 new mode 100755 index 77a6367..ce32e3a --- a/Cards/Sources/DetailViewController.swift +++ b/Cards/Sources/DetailViewController.swift @@ -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 } @@ -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) @@ -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 { @@ -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) } @@ -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 } @@ -185,7 +194,6 @@ extension DetailViewController: UIScrollViewDelegate { scrollView.frame.origin.y -= y/2 } - guard offset < 60 else { dismissVC(); return } card.delegate?.cardDetailIsScrolling?(card: card) } @@ -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 { diff --git a/Cards/Sources/LayoutHelper.swift b/Cards/Sources/LayoutHelper.swift old mode 100644 new mode 100755 index 26b048b..8595878 --- a/Cards/Sources/LayoutHelper.swift +++ b/Cards/Sources/LayoutHelper.swift @@ -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 } } diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index b345b2b..e0bf94a 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -25,7 +25,7 @@ 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 = ""; }; + 6D3CD3321F9BD40B00C0592C /* Cards.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Cards.podspec; path = ../Cards.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 6D3CD3411F9BDE0D00C0592C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 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 = ""; }; @@ -133,7 +133,6 @@ 6D436D501F9BD34600B05FA6 /* Frameworks */, 6D436D511F9BD34600B05FA6 /* Resources */, F00B028E32056EAAB78B17B6 /* [CP] Embed Pods Frameworks */, - 1F4F32B159D4D16417DBCB18 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -156,6 +155,7 @@ TargetAttributes = { 6D436D521F9BD34600B05FA6 = { CreatedOnToolsVersion = 9.0.1; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; }; @@ -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; @@ -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; @@ -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; diff --git a/Demo/Demo/AppDelegate.swift b/Demo/Demo/AppDelegate.swift index b0dd171..860903d 100644 --- a/Demo/Demo/AppDelegate.swift +++ b/Demo/Demo/AppDelegate.swift @@ -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 } diff --git a/Demo/Demo/Storyboards/Base.lproj/Main.storyboard b/Demo/Demo/Storyboards/Base.lproj/Main.storyboard index 55e4872..a44577c 100755 --- a/Demo/Demo/Storyboards/Base.lproj/Main.storyboard +++ b/Demo/Demo/Storyboards/Base.lproj/Main.storyboard @@ -1,13 +1,11 @@ - + - - - + @@ -135,16 +133,20 @@ - - + + + + + + @@ -165,8 +167,10 @@ + + @@ -178,7 +182,7 @@ - + @@ -276,7 +280,7 @@