-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardCell.swift
55 lines (36 loc) · 1.54 KB
/
CardCell.swift
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
//
// CardCell.swift
// Day99Challange
//
// Created by Eren Erinanc on 14.05.2021.
//
import UIKit
class CardCell: UICollectionViewCell {
@IBOutlet var frontImageView: UIImageView!
@IBOutlet var backImageView: UIImageView!
var card: Card?
func setCard(_ card: Card) {
// Keep track of the card that gets passed in
self.card = card
let path = Bundle.main.path(forResource: "\(card.imageName).png", ofType: nil)!
frontImageView.image = UIImage(contentsOfFile: path)
if card.isFlipped {
UIView.transition(from: backImageView, to: frontImageView, duration: 0, options: [.transitionFlipFromRight, .showHideTransitionViews])
} else {
UIView.transition(from: frontImageView, to: backImageView, duration: 0, options: [.transitionFlipFromRight, .showHideTransitionViews])
}
}
func flip() {
let transitionOption: UIView.AnimationOptions = [.transitionFlipFromRight, .showHideTransitionViews]
UIView.transition(from: backImageView, to: frontImageView, duration: 0.3, options: transitionOption)
}
func flipBack() {
let transitionOption: UIView.AnimationOptions = [.transitionFlipFromRight, .showHideTransitionViews]
UIView.transition(from: frontImageView, to: backImageView, duration: 0.3, options: transitionOption)
}
func remove() {
// // TODO: Animate it
frontImageView.alpha = 0
backImageView.alpha = 0
}
}