-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathPattern3ViewController.swift
More file actions
63 lines (59 loc) · 2.57 KB
/
Pattern3ViewController.swift
File metadata and controls
63 lines (59 loc) · 2.57 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
56
57
58
59
60
61
62
//
// Pattern3ViewController.swift
// Example
//
// Created by iamchiwon on 2018. 3. 8..
// Copyright © 2018년 hiroyuki yoshida. All rights reserved.
//
import UIKit
import InfiniteCollectionView
final class Pattern3ViewController: UIViewController {
var itemsCount: Int = 5
@IBOutlet weak var collectionView: InfiniteCollectionView! {
didSet {
collectionView.infiniteDataSource = self
collectionView.infiniteDelegate = self
collectionView.register(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier)
}
}
@IBOutlet weak var layout: UICollectionViewFlowLayout! {
didSet {
layout.itemSize = UIScreen.main.bounds.size
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
NotificationCenter.default.addObserver(self, selector: #selector(Pattern1ViewController.rotate(_:)), name: .UIDeviceOrientationDidChange, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: .UIDeviceOrientationDidChange, object: nil)
}
static func createFromStoryboard() -> Pattern3ViewController {
let storyboard = UIStoryboard(name: "Pattern3", bundle: nil)
return storyboard.instantiateInitialViewController() as! Pattern3ViewController
}
@objc func rotate(_ notification: Notification) {
layout.itemSize = UIScreen.main.bounds.size
layout.invalidateLayout()
collectionView.rotate(notification)
collectionView.layoutIfNeeded()
collectionView.setNeedsLayout()
}
}
// MARK: - InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate
extension Pattern3ViewController: InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate {
func number(ofItems collectionView: UICollectionView) -> Int {
return itemsCount
}
func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCollectionViewCell.identifier, for: dequeueIndexPath) as! ImageCollectionViewCell
cell.configure(indexPath: usableIndexPath)
return cell
}
func infiniteCollectionView(_ collectionView: UICollectionView, didSelectItemAt usableIndexPath: IndexPath) {
print("didSelectItemAt: \(usableIndexPath.item)")
}
func scrollView(_ scrollView: UIScrollView, pageIndex: Int) {
print("scrollView: \(pageIndex)")
}
}