-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollectionViewController.swift
84 lines (61 loc) · 2.79 KB
/
collectionViewController.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
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
//
// collectionViewController.swift
// game
//
// Created by Александр on 12.08.17.
// Copyright © 2017 Александр. All rights reserved.
//
import UIKit
class collectionViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var destination : [String] = []
var destinationPhoto : [String] = []
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
for mas in destination{
let summa = ("\(mas)"+"_1")
destinationPhoto.append(summa)
}
print("\(destinationPhoto)")
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return destination.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "theCell", for: indexPath) as! CollectionViewCell
cell.imageCollection.image = UIImage(named: destination[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
dataPhoto(tDataPhoto: destinationPhoto[indexPath.row])
}
//MARK: HeaderView
func collectionView(_ collectionView: UICollectionView,viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind,withReuseIdentifier: "HEADER", for: indexPath) as! headerReusableView
headerView.arrowBack.addTarget(self, action: #selector(collectionViewController.backs), for: .touchUpInside)
return headerView
default:
fatalError("Unexpected element kind")
}
}
func dataPhoto(tDataPhoto: String){
let vc = storyboard?.instantiateViewController(withIdentifier: "PHOTO_VIEW") as! photoViewController
vc.destinationPhotoTwo = tDataPhoto
self.present(vc, animated: true, completion: nil)
}
func backs(){
self.dismiss(animated: true, completion: nil)
}
}
extension UIImage {
func imageResize (sizeChange:CGSize)-> UIImage{
let hasAlpha = true
let scale: CGFloat = 10 // Use scale factor of main screen
UIGraphicsBeginImageContextWithOptions(sizeChange, !hasAlpha, scale)
self.draw(in: CGRect(origin: CGPoint.zero, size: sizeChange))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
return scaledImage!
}
}