Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Koloda
- //
- // Created by Eugene Andreyev on 4/23/15.
- // Copyright (c) 2015 Eugene Andreyev. All rights reserved.
- //
- import UIKit
- import Koloda
- private var numberOfCards: Int = 5
- class ViewController: UIViewController {
- @IBOutlet weak var kolodaView: KolodaView!
- var imgLikeWidth : Int = 50
- var imgLikeHeight : Int = 50
- var imgDislikeWidth : Int = 50
- var imgDislikeHeight : Int = 50
- var products = [Product]()
- @IBOutlet var imgLike : UIImageView!
- @IBOutlet var imgDislike : UIImageView!
- override func viewDidLoad() {
- super.viewDidLoad()
- kolodaView.dataSource = self
- kolodaView.delegate = self
- let p = Product()
- p.testo = "TESTO"
- p.url_image = "https://www.comune.casina.re.it/wp-content/uploads/2019/07/Sarzano-panoramica-Maggio-2019-ridotta.jpg"
- let p1 = Product()
- p1.testo = "TESTO"
- p1.url_image = "https://www.comune.casina.re.it/wp-content/uploads/2019/07/Sarzano-panoramica-Maggio-2019-ridotta.jpg"
- self.products.append(p)
- self.products.append(p1)
- print("AGGIUNTA PRODOTTI")
- self.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
- }
- }
- extension ViewController: KolodaViewDataSource, KolodaViewDelegate {
- //--------------------------------------------------------------------------
- // MARK: Cards Delegate
- //--------------------------------------------------------------------------
- func koloda(_ koloda: KolodaView, didSwipeCardAt index: Int, in direction: SwipeResultDirection) {
- let product = self.products[index]
- //self.imgLike.alpha = 0
- //self.imgDislike.alpha = 0
- switch direction {
- case .left:
- print("LEFT DIRECTION")
- self.kolodaView.swipe(.left)
- //self.dislike(product: product, method: .swipe)
- break
- case .right:
- print("RIGHT DIRECTION")
- self.kolodaView.swipe(.right)
- //self.like(product: product, method: .swipe)
- break
- default: break
- }
- }
- func kolodaPanFinished(_ koloda: KolodaView, card: DraggableCardView) {
- // self.imgLike.animate(alpha: 0, duracy: 0.1)
- //self.imgDislike.animate(alpha: 0, duracy: 0.1)
- }
- func koloda(_ koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, in direction: SwipeResultDirection) {
- if direction == .right {
- print("RIGHT")
- let d = max(finishPercentage - 20, 0) / 100
- /*let img = (direction == .right ? self.imgLike : self.imgDislike)
- let imgWidth = (direction == .right ? self.imgLikeWidth : self.imgDislikeWidth)
- let otherImg = (direction == .right ? self.imgDislike : self.imgLike)
- //img?.alpha = min(d, 1) * 1.0
- //imgWidth.constant = d * 200
- //otherImg?.alpha = 0
- img?.animateLayoutIfNeeded()*/
- }
- }
- func manuallyAnimateLike() { self.manuallyAnimate(didLike: true) }
- func manuallyAnimateDislike() { self.manuallyAnimate(didLike: false) }
- func manuallyAnimate(didLike: Bool) {
- // ...
- }
- func koloda(_ koloda: KolodaView, didSelectCardAt index: Int) {
- //FCAnalytics.did(.tapOnProduct, self.currentProduct, from: .tinder)
- //ProductsMenu.showDetails(of: self.currentProduct, from: .tinder)
- }
- func kolodaDidRunOutOfCards(_ koloda: KolodaView) {
- koloda.reloadData()
- }
- func koloda(_ koloda: KolodaView, didShowCardAt index: Int) {
- //FCAnalytics.did(.see, self.products[index], from: .tinder)
- let remaining = self.products.count - index
- /*if remaining < 15 && !self.productsProvider.fetchInProgress {
- self.productsProvider.fetchBatch()
- }*/
- }
- //--------------------------------------------------------------------------
- // MARK: Cards Data Source
- //--------------------------------------------------------------------------
- func kolodaNumberOfCards(_ koloda:KolodaView) -> Int {
- return self.products.count
- }
- func kolodaSpeedThatCardShouldDrag(_ koloda: KolodaView) -> DragSpeed {
- return .fast
- }
- func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? {
- return 0.8
- }
- func koloda(_ koloda: KolodaView, viewForCardAt index: Int) -> UIView {
- let card = Bundle.main.loadNibNamed(
- "ProductCardView",
- owner: self,
- options: nil
- )!.first as! ProductCardView
- card.frame = kolodaView.bounds
- print("SETUP")
- card.setup(withProduct: self.products[index])
- return card
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement