-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPhotoViewController.swift
More file actions
55 lines (45 loc) · 1.87 KB
/
PhotoViewController.swift
File metadata and controls
55 lines (45 loc) · 1.87 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
//
// PhotoViewController.swift
// SolarSystem
//
// Created by Neha Thakore on 11/8/17.
// Copyright © 2017 Neha Thakore. All rights reserved.
//
import UIKit
class PhotoViewController: UIViewController {
@IBOutlet weak var photoCollectionView: UICollectionView!
var imageCellModels = [PlanetImageCellModel]()
var startingIndexPath: IndexPath?
@IBAction func closeButton(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
photoCollectionView.delegate = self
photoCollectionView.dataSource = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let index = startingIndexPath {
photoCollectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: false)
}
}
}
extension PhotoViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageCellModels.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhotoCollectionViewCell", for: indexPath) as? PhotoCollectionViewCell else {
return UICollectionViewCell()
}
let imageModel = imageCellModels[indexPath.item]
cell.cellModel = imageModel
return cell
}
}
extension PhotoViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: photoCollectionView.bounds.width, height: photoCollectionView.bounds.height)
}
}