Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // Koloda
  4. //
  5. // Created by Eugene Andreyev on 4/23/15.
  6. // Copyright (c) 2015 Eugene Andreyev. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Koloda
  11.  
  12. private var numberOfCards: Int = 5
  13.  
  14. class ViewController: UIViewController {
  15.  
  16. @IBOutlet weak var kolodaView: KolodaView!
  17. var imgLikeWidth : Int = 50
  18. var imgLikeHeight : Int = 50
  19. var imgDislikeWidth : Int = 50
  20. var imgDislikeHeight : Int = 50
  21. var products = [Product]()
  22. @IBOutlet var imgLike : UIImageView!
  23. @IBOutlet var imgDislike : UIImageView!
  24.  
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27.  
  28. kolodaView.dataSource = self
  29. kolodaView.delegate = self
  30.  
  31. let p = Product()
  32. p.testo = "TESTO"
  33. p.url_image = "https://www.comune.casina.re.it/wp-content/uploads/2019/07/Sarzano-panoramica-Maggio-2019-ridotta.jpg"
  34. let p1 = Product()
  35. p1.testo = "TESTO"
  36. p1.url_image = "https://www.comune.casina.re.it/wp-content/uploads/2019/07/Sarzano-panoramica-Maggio-2019-ridotta.jpg"
  37. self.products.append(p)
  38. self.products.append(p1)
  39.  
  40. print("AGGIUNTA PRODOTTI")
  41.  
  42. self.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
  43. }
  44.  
  45. }
  46.  
  47. extension ViewController: KolodaViewDataSource, KolodaViewDelegate {
  48.  
  49. //--------------------------------------------------------------------------
  50. // MARK: Cards Delegate
  51. //--------------------------------------------------------------------------
  52.  
  53. func koloda(_ koloda: KolodaView, didSwipeCardAt index: Int, in direction: SwipeResultDirection) {
  54.  
  55. let product = self.products[index]
  56.  
  57. //self.imgLike.alpha = 0
  58. //self.imgDislike.alpha = 0
  59.  
  60. switch direction {
  61.  
  62. case .left:
  63. print("LEFT DIRECTION")
  64. self.kolodaView.swipe(.left)
  65. //self.dislike(product: product, method: .swipe)
  66. break
  67.  
  68. case .right:
  69. print("RIGHT DIRECTION")
  70. self.kolodaView.swipe(.right)
  71. //self.like(product: product, method: .swipe)
  72. break
  73.  
  74. default: break
  75. }
  76. }
  77.  
  78. func kolodaPanFinished(_ koloda: KolodaView, card: DraggableCardView) {
  79. // self.imgLike.animate(alpha: 0, duracy: 0.1)
  80. //self.imgDislike.animate(alpha: 0, duracy: 0.1)
  81. }
  82.  
  83. func koloda(_ koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, in direction: SwipeResultDirection) {
  84.  
  85. if direction == .right {
  86. print("RIGHT")
  87. let d = max(finishPercentage - 20, 0) / 100
  88.  
  89. /*let img = (direction == .right ? self.imgLike : self.imgDislike)
  90. let imgWidth = (direction == .right ? self.imgLikeWidth : self.imgDislikeWidth)
  91. let otherImg = (direction == .right ? self.imgDislike : self.imgLike)
  92. //img?.alpha = min(d, 1) * 1.0
  93. //imgWidth.constant = d * 200
  94. //otherImg?.alpha = 0
  95.  
  96. img?.animateLayoutIfNeeded()*/
  97. }
  98. }
  99.  
  100. func manuallyAnimateLike() { self.manuallyAnimate(didLike: true) }
  101. func manuallyAnimateDislike() { self.manuallyAnimate(didLike: false) }
  102.  
  103. func manuallyAnimate(didLike: Bool) {
  104. // ...
  105. }
  106.  
  107. func koloda(_ koloda: KolodaView, didSelectCardAt index: Int) {
  108. //FCAnalytics.did(.tapOnProduct, self.currentProduct, from: .tinder)
  109. //ProductsMenu.showDetails(of: self.currentProduct, from: .tinder)
  110. }
  111.  
  112. func kolodaDidRunOutOfCards(_ koloda: KolodaView) {
  113. koloda.reloadData()
  114. }
  115.  
  116. func koloda(_ koloda: KolodaView, didShowCardAt index: Int) {
  117.  
  118. //FCAnalytics.did(.see, self.products[index], from: .tinder)
  119.  
  120. let remaining = self.products.count - index
  121. /*if remaining < 15 && !self.productsProvider.fetchInProgress {
  122. self.productsProvider.fetchBatch()
  123. }*/
  124. }
  125.  
  126. //--------------------------------------------------------------------------
  127. // MARK: Cards Data Source
  128. //--------------------------------------------------------------------------
  129.  
  130. func kolodaNumberOfCards(_ koloda:KolodaView) -> Int {
  131. return self.products.count
  132. }
  133.  
  134. func kolodaSpeedThatCardShouldDrag(_ koloda: KolodaView) -> DragSpeed {
  135. return .fast
  136. }
  137.  
  138. func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? {
  139. return 0.8
  140. }
  141.  
  142. func koloda(_ koloda: KolodaView, viewForCardAt index: Int) -> UIView {
  143. let card = Bundle.main.loadNibNamed(
  144. "ProductCardView",
  145. owner: self,
  146. options: nil
  147. )!.first as! ProductCardView
  148.  
  149. card.frame = kolodaView.bounds
  150. print("SETUP")
  151. card.setup(withProduct: self.products[index])
  152.  
  153. return card
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement