-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImagePickerCollectionView.swift
More file actions
executable file
·56 lines (43 loc) · 1.64 KB
/
ImagePickerCollectionView.swift
File metadata and controls
executable file
·56 lines (43 loc) · 1.64 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
//
// ImagePickerCollectionView.swift
// ImagePickerSheet
//
// Created by Laurin Brandner on 07/09/14.
// Copyright (c) 2014 Laurin Brandner. All rights reserved.
//
import UIKit
class ImagePickerCollectionView: UICollectionView {
var bouncing: Bool {
return contentOffset.x < -contentInset.left || contentOffset.x + frame.width > contentSize.width + contentInset.right
}
var imagePreviewLayout: ImagePreviewFlowLayout {
return collectionViewLayout as! ImagePreviewFlowLayout
}
// MARK: - Initialization
init() {
super.init(frame: CGRectZero, collectionViewLayout: ImagePreviewFlowLayout())
initialize()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
private func initialize() {
panGestureRecognizer.addTarget(self, action: "handlePanGesture:")
}
// MARK: - Panning
@objc private func handlePanGesture(gestureRecognizer: UIPanGestureRecognizer) {
if gestureRecognizer.state == .Ended {
let translation = gestureRecognizer.translationInView(self)
if translation == CGPointZero {
if !bouncing {
let possibleIndexPath = indexPathForItemAtPoint(gestureRecognizer.locationInView(self))
if let indexPath = possibleIndexPath {
selectItemAtIndexPath(indexPath, animated: false, scrollPosition: .None)
delegate?.collectionView?(self, didSelectItemAtIndexPath: indexPath)
}
}
}
}
}
}