質問編集履歴
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,120 +40,120 @@
|
|
40
40
|
|
41
41
|
addLongTapGesture()
|
42
42
|
|
43
|
+
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
@IBAction func tapButton(_ sender: Any) {
|
48
|
+
|
49
|
+
let pickerController = DKImagePickerController()
|
50
|
+
|
51
|
+
pickerController.maxSelectableCount = 4 - (assets?.count ?? 0)
|
52
|
+
|
53
|
+
pickerController.UIDelegate = CustumUIDelegate()
|
54
|
+
|
55
|
+
pickerController.didSelectAssets = { [unowned self] (assets: [DKAsset]) in
|
56
|
+
|
57
|
+
self.assets = assets
|
58
|
+
|
59
|
+
self.collectionView.reloadData()
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
present(pickerController, animated: true, completion: nil)
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
func addLongTapGesture() {
|
72
|
+
|
73
|
+
let longTapGesture = UILongPressGestureRecognizer(target:self,action:#selector(longTap(gesture:)))
|
74
|
+
|
75
|
+
collectionView.addGestureRecognizer(longTapGesture)
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
@objc func longTap(gesture:UILongPressGestureRecognizer){
|
82
|
+
|
83
|
+
switch gesture.state{
|
84
|
+
|
85
|
+
// ロングタップの開始時
|
86
|
+
|
87
|
+
case.began:
|
88
|
+
|
89
|
+
guard
|
90
|
+
|
91
|
+
let selectedIndexPath = collectionView.indexPathForItem(at:gesture.location(in:collectionView))else{
|
92
|
+
|
93
|
+
break
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
collectionView.beginInteractiveMovementForItem(at:selectedIndexPath)
|
98
|
+
|
99
|
+
// セルの移動中
|
100
|
+
|
101
|
+
case.changed:
|
102
|
+
|
103
|
+
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in:gesture.view))
|
104
|
+
|
105
|
+
// セルの移動完了時
|
106
|
+
|
107
|
+
case.ended:
|
108
|
+
|
109
|
+
collectionView.endInteractiveMovement()
|
110
|
+
|
111
|
+
default:
|
112
|
+
|
113
|
+
collectionView.cancelInteractiveMovement()
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
126
|
+
|
127
|
+
return self.assets?.count ?? 0
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
134
|
+
|
135
|
+
let asset = self.assets![indexPath.row]
|
136
|
+
|
137
|
+
var cell: UICollectionViewCell?
|
138
|
+
|
139
|
+
var imageView: UIImageView?
|
140
|
+
|
43
141
|
|
44
142
|
|
143
|
+
if asset.type == .photo {
|
144
|
+
|
145
|
+
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellImage", for: indexPath)
|
146
|
+
|
147
|
+
imageView = cell?.contentView.viewWithTag(1) as? UIImageView
|
148
|
+
|
45
|
-
}
|
149
|
+
}
|
46
|
-
|
47
|
-
|
150
|
+
|
48
|
-
|
49
|
-
let pickerController = DKImagePickerController()
|
50
|
-
|
51
|
-
pickerController.maxSelectableCount = 4 - (assets?.count ?? 0)
|
52
|
-
|
53
|
-
pickerController.UIDelegate = CustumUIDelegate()
|
54
|
-
|
55
|
-
pickerController.didSelectAssets = { [unowned self] (assets: [DKAsset]) in
|
56
|
-
|
57
|
-
|
151
|
+
//表示
|
58
|
-
|
152
|
+
|
59
|
-
|
153
|
+
if let imageView = imageView {
|
60
154
|
|
61
155
|
|
62
156
|
|
63
|
-
}
|
64
|
-
|
65
|
-
present(pickerController, animated: true, completion: nil)
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
func addLongTapGesture() {
|
72
|
-
|
73
|
-
let longTapGesture = UILongPressGestureRecognizer(target:self,action:#selector(longTap(gesture:)))
|
74
|
-
|
75
|
-
collectionView.addGestureRecognizer(longTapGesture)
|
76
|
-
|
77
|
-
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@objc func longTap(gesture:UILongPressGestureRecognizer){
|
82
|
-
|
83
|
-
switch gesture.state{
|
84
|
-
|
85
|
-
// ロングタップの開始時
|
86
|
-
|
87
|
-
case.began:
|
88
|
-
|
89
|
-
guard
|
90
|
-
|
91
|
-
let selectedIndexPath = collectionView.indexPathForItem(at:gesture.location(in:collectionView))else{
|
92
|
-
|
93
|
-
break
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
collectionView.beginInteractiveMovementForItem(at:selectedIndexPath)
|
98
|
-
|
99
|
-
// セルの移動中
|
100
|
-
|
101
|
-
case.changed:
|
102
|
-
|
103
|
-
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in:gesture.view))
|
104
|
-
|
105
|
-
// セルの移動完了時
|
106
|
-
|
107
|
-
case.ended:
|
108
|
-
|
109
|
-
collectionView.endInteractiveMovement()
|
110
|
-
|
111
|
-
default:
|
112
|
-
|
113
|
-
collectionView.cancelInteractiveMovement()
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
126
|
-
|
127
|
-
return self.assets?.count ?? 0
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
134
|
-
|
135
|
-
let asset = self.assets![indexPath.row]
|
136
|
-
|
137
|
-
var cell: UICollectionViewCell?
|
138
|
-
|
139
|
-
var imageView: UIImageView?
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
if asset.type == .photo {
|
144
|
-
|
145
|
-
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellImage", for: indexPath)
|
146
|
-
|
147
|
-
imageView = cell?.contentView.viewWithTag(1) as? UIImageView
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
//表示
|
152
|
-
|
153
|
-
if let imageView = imageView {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
157
|
asset.fetchFullScreenImage(completeBlock: { image, info in
|
158
158
|
|
159
159
|
imageView.image = image
|