-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathViewController.swift
More file actions
105 lines (88 loc) · 3.12 KB
/
Copy pathViewController.swift
File metadata and controls
105 lines (88 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// ViewController.swift
// Example
//
// Created by HideakiTouhara on 2018/02/26.
// Copyright © 2018年 HideakiTouhara. All rights reserved.
//
import UIKit
import Poi
class ViewController: UIViewController, PoiViewDataSource, PoiViewDelegate {
@IBOutlet weak var poiView: PoiView!
var sampleCards = [Card]()
let alternateSampleCards: [Card] = {
var cards: [Card] = []
let texts = ["ramen", "steak", "sushi"]
let images = [#imageLiteral(resourceName: "ramen"), #imageLiteral(resourceName: "meat"), #imageLiteral(resourceName: "sushi")]
for i in (0..<3) {
let card = UINib(nibName: "Card", bundle: nil).instantiate(withOwner: self, options: nil)[0] as! Card
card.prepareUI(text: texts[i], img: images[i])
cards.append(card)
}
return cards
}()
var usesAlternate: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
createViews()
poiView.dataSource = self
poiView.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
private func createViews() {
for i in (0..<2) {
let texts = ["sushi", "steak"]
let images = [#imageLiteral(resourceName: "sushi"), #imageLiteral(resourceName: "meat")]
let card = UINib(nibName: "Card", bundle: nil).instantiate(withOwner: self, options: nil)[0] as! Card
card.prepareUI(text: texts[i], img: images[i])
sampleCards.append(card)
}
}
// MARK: PoiViewDataSource
func numberOfCards(_ poi: PoiView) -> Int {
return usesAlternate ? alternateSampleCards.count : sampleCards.count
}
func poi(_ poi: PoiView, viewForCardAt index: Int) -> UIView {
return usesAlternate ? alternateSampleCards[index] : sampleCards[index]
}
func poi(_ poi: PoiView, viewForCardOverlayFor direction: SwipeDirection) -> UIImageView? {
switch direction {
case .right:
let good = UIImageView(image: #imageLiteral(resourceName: "good"))
good.tintColor = UIColor.green
return good
case .left:
let bad = UIImageView(image: #imageLiteral(resourceName: "bad"))
bad.tintColor = UIColor.red
return bad
}
}
// MARK: PoiViewDelegate
func poi(_ poi: PoiView, didSwipeCardAt: Int, in direction: SwipeDirection) {
switch direction {
case .left:
print("left")
case .right:
print("right")
}
}
func poi(_ poi: PoiView, runOutOfCardAt: Int, in direction: SwipeDirection) {
print("last")
}
// MARK: IBAction
@IBAction func OKAction(_ sender: UIButton) {
poiView.swipeCurrentCard(to: .right)
}
@IBAction func cancelAction(_ sender: UIButton) {
poiView.swipeCurrentCard(to: .left)
}
@IBAction func undo(_ sender: UIButton) {
poiView.undo()
}
@IBAction func reload(_ sender: Any) {
usesAlternate = !usesAlternate
poiView.reloadData()
}
}