回答編集履歴

1

追記

2017/12/05 13:48

投稿

izkn
izkn

スコア1698

test CHANGED
@@ -1,3 +1,195 @@
1
+ ## 追記
2
+
3
+
4
+
5
+ 参考にしたものが古い。最低限動くようにしました。`!`のところに`nil`がくればアプリが落ちます。
6
+
7
+
8
+
9
+ ```swift
10
+
11
+ import UIKit
12
+
13
+
14
+
15
+ class ViewController: UIViewController, MDCSwipeToChooseDelegate {
16
+
17
+
18
+
19
+ var swipeCount = 0
20
+
21
+ var photoURL = [
22
+
23
+ // "http://up.gc-img.net/post_img_web/2013/03/a3a43755438b42d881929eefc7161191_0.jpeg",
24
+
25
+ "https://up.gc-img.net/post_img_web/2013/03/a3a43755438b42d881929eefc7161191_0.jpeg",
26
+
27
+ // "http://pic.prepics-cdn.com/pib1298076039/5731792_218x291.gif",
28
+
29
+ "https://pic.prepics-cdn.com/pib1298076039/5731792_218x291.gif",
30
+
31
+ // "http://omosoku.com/wp-content/uploads/misawa-225x300.gif"
32
+
33
+ "https://leverages.jp/images/common/LV01s.jpg"
34
+
35
+ ]
36
+
37
+
38
+
39
+ override func viewDidLoad() {
40
+
41
+ super.viewDidLoad()
42
+
43
+ // Do any additional setup after loading the view, typically from a nib.
44
+
45
+
46
+
47
+ // let swipeView1 = createSwipeView(photoURL[0])
48
+
49
+ let swipeView1 = createSwipeView(url: photoURL[0])
50
+
51
+ self.view.addSubview(swipeView1)
52
+
53
+
54
+
55
+ // let swipeView2 = createSwipeView(photoURL[1])
56
+
57
+ let swipeView2 = createSwipeView(url: photoURL[1])
58
+
59
+ self.view.insertSubview(swipeView2, belowSubview: swipeView1)
60
+
61
+
62
+
63
+ // let swipeView3 = createSwipeView(photoURL[2])
64
+
65
+ let swipeView3 = createSwipeView(url: photoURL[2])
66
+
67
+ self.view.insertSubview(swipeView3, belowSubview: swipeView2)
68
+
69
+
70
+
71
+ }
72
+
73
+
74
+
75
+ func createSwipeView(url: String) -> UIView {
76
+
77
+ let options = MDCSwipeToChooseViewOptions()
78
+
79
+ options.delegate = self
80
+
81
+ options.likedText = "Like"
82
+
83
+ // options.likedColor = UIColor.greenColor()
84
+
85
+ options.likedColor = UIColor.green
86
+
87
+ options.nopeText = "Later"
88
+
89
+ // options.nopeColor = UIColor.lightGrayColor()
90
+
91
+ options.nopeColor = UIColor.lightGray
92
+
93
+
94
+
95
+ let swipeView = MDCSwipeToChooseView(
96
+
97
+ frame: CGRect(
98
+
99
+ x: 0,
100
+
101
+ y: 100,
102
+
103
+ width: self.view.bounds.size.width,
104
+
105
+ height: self.view.bounds.size.height - 300
106
+
107
+ ),
108
+
109
+ options: options
110
+
111
+ )
112
+
113
+ // let imageURL = NSURL(string: url)
114
+
115
+ let imageURL = URL(string: url)
116
+
117
+ // swipeView.imageView.image = UIImage(data: NSData(contentsOfURL: imageURL!)!)
118
+
119
+
120
+
121
+ do {
122
+
123
+
124
+
125
+ try swipeView?.imageView.image = UIImage(data: Data(contentsOf: imageURL!))
126
+
127
+
128
+
129
+ } catch {
130
+
131
+
132
+
133
+ fatalError()
134
+
135
+
136
+
137
+ }
138
+
139
+
140
+
141
+ // return swipeView
142
+
143
+ return swipeView!
144
+
145
+ }
146
+
147
+
148
+
149
+
150
+
151
+ func view(view: UIView!, wasChosenWithDirection direction: MDCSwipeDirection) {
152
+
153
+ // if (direction == MDCSwipeDirection.Left) {
154
+
155
+ if (direction == MDCSwipeDirection.left) {
156
+
157
+ } else {
158
+
159
+ }
160
+
161
+ // swipeCount++
162
+
163
+ swipeCount += 1
164
+
165
+ }
166
+
167
+
168
+
169
+
170
+
171
+ override func didReceiveMemoryWarning() {
172
+
173
+ super.didReceiveMemoryWarning()
174
+
175
+ // Dispose of any resources that can be recreated.
176
+
177
+ }
178
+
179
+
180
+
181
+
182
+
183
+ }
184
+
185
+
186
+
187
+
188
+
189
+ ```
190
+
191
+
192
+
1
193
  ## 環境
2
194
 
3
195