-
Notifications
You must be signed in to change notification settings - Fork 0
/
GalleryViewController.swift
59 lines (47 loc) · 2.06 KB
/
GalleryViewController.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
56
57
58
59
//
// GalleryViewController.swift
// StoryboardSnippets
//
// Created by Elliott Io on 4/25/20.
// Copyright © 2020 elliott io. All rights reserved.
//
import Foundation
import UIKit
class GalleryViewController : UICollectionViewController {
let cellId = "photoCell"
let assets = ["goodVibesOnly", // https://www.instagram.com/p/Bji3MLiAP3r/
"elCapitan", // https://www.instagram.com/p/Bo3S28mHgF5/
"tagYoureIt", // https://www.instagram.com/p/BiI5h4BFbrt/
"unionStation", // https://www.instagram.com/p/BiYMOJEF-0N/
"tunnel2ndSt", // https://www.instagram.com/p/Bir4CY_FxAs/
// "charredTree", // https://www.instagram.com/p/Bj5TJvvF9ZO/
]
let sharedPhotoAlbum = CustomPhotoAlbum.sharedInstance
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.decelerationRate = .fast
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("photo selected at row \(indexPath.row)")
if let cell = collectionView.cellForItem(at: indexPath) as? PhotoCell {
cell.selected(true)
}
}
override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
print("photo selected at row \(indexPath.row)")
if let cell = collectionView.cellForItem(at: indexPath) as? PhotoCell {
cell.selected(false)
}
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return assets.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let assetName = assets[indexPath.row]
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as? PhotoCell,
let image = UIImage(named: assetName) else {
return PhotoCell.init() }
cell.set(image)
return cell
}
}