質問編集履歴
1
すべて解決いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,417 +7,3 @@
|
|
7
7
|
なぜ勝手に画像が拡大、縮小するのか原因が分かりません。
|
8
8
|
|
9
9
|
これはレイアウトの問題なのか、アニメーションの問題なのか、どなたか解決策を教えてくださると幸いです。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
![![イメージ説明](20e58331504f63e5c677e63a7d2d3b4d.gif)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
こちらが遷移する前のVCです。
|
18
|
-
|
19
|
-
```ここに言語を入力
|
20
|
-
|
21
|
-
class FeedController: UICollectionViewController{
|
22
|
-
|
23
|
-
let currentUser = CurrentUser.shared
|
24
|
-
|
25
|
-
private let reuseIdentifier = "TweetCell"
|
26
|
-
|
27
|
-
private let headeerIdentifier = "TweetHeader"
|
28
|
-
|
29
|
-
private var profileImage: UIImage?
|
30
|
-
|
31
|
-
var viewControllers: [UIViewController] = []
|
32
|
-
|
33
|
-
private var user: Results<User>! {
|
34
|
-
|
35
|
-
didSet {
|
36
|
-
|
37
|
-
guard let nav = viewControllers[0] as? UINavigationController else { return }
|
38
|
-
|
39
|
-
guard let feed = nav.viewControllers.first as? FeedController else { return }
|
40
|
-
|
41
|
-
feed.user = user
|
42
|
-
|
43
|
-
configureLeftBarButton()
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
}
|
48
|
-
|
49
|
-
private var tweets: [Tweet] = [Tweet]() {
|
50
|
-
|
51
|
-
didSet { collectionView.reloadData() }
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
var selectedImageView = UIImageView()
|
56
|
-
|
57
|
-
var pageViewController: UIPageViewController {
|
58
|
-
|
59
|
-
return self.children[0] as! UIPageViewController
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
var currentViewController: PhotoZoomViewController {
|
64
|
-
|
65
|
-
return self.pageViewController.viewControllers![0] as! PhotoZoomViewController
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
var currentLeftSafeAreaInset : CGFloat = 0.0
|
70
|
-
|
71
|
-
var currentRightSafeAreaInset : CGFloat = 0.0
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
override func viewDidLoad() {
|
76
|
-
|
77
|
-
super.viewDidLoad()
|
78
|
-
|
79
|
-
configureUI()
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
override func viewSafeAreaInsetsDidChange() {
|
86
|
-
|
87
|
-
if #available(iOS 11, *) {
|
88
|
-
|
89
|
-
self.currentLeftSafeAreaInset = self.view.safeAreaInsets.left
|
90
|
-
|
91
|
-
self.currentRightSafeAreaInset = self.view.safeAreaInsets.right
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
private func configureUI(){
|
100
|
-
|
101
|
-
collectionView.register(TweetCell.self, forCellWithReuseIdentifier: reuseIdentifier)
|
102
|
-
|
103
|
-
collectionView.backgroundColor = UIColor(named: "Mode")
|
104
|
-
|
105
|
-
configureLeftBarButton()
|
106
|
-
|
107
|
-
}
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
extension FeedController {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
120
|
-
|
121
|
-
return tweets.count
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
128
|
-
|
129
|
-
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! TweetCell
|
130
|
-
|
131
|
-
cell.delegate = self
|
132
|
-
|
133
|
-
let tweetObject = tweets[indexPath.row]
|
134
|
-
|
135
|
-
cell.tweets = tweetObject
|
136
|
-
|
137
|
-
cell.captionLabel.text = tweetObject.caption
|
138
|
-
|
139
|
-
cell.infoLabel.attributedText = getTitle(for: indexPath.row)
|
140
|
-
|
141
|
-
cell.imageURLs = tweetObject.imageURLs
|
142
|
-
|
143
|
-
cell.configure()
|
144
|
-
|
145
|
-
return cell
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
extension FeedController: UICollectionViewDelegateFlowLayout {
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
160
|
-
|
161
|
-
let tweetObject = tweets[indexPath.row]
|
162
|
-
|
163
|
-
let height = calcSize(width: view.frame.width, text: tweetObject.caption).height
|
164
|
-
|
165
|
-
let imageContainerHeight: CGFloat = tweetObject.imageURLs.isEmpty ? 0 : 160
|
166
|
-
|
167
|
-
return CGSize(width: view.frame.width, height: height + 80 + imageContainerHeight)
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
extension FeedController: TweetCellDelegate {
|
178
|
-
|
179
|
-
func selectedImageView(_ imageView: UIImageView, tag: Int, imageURLs: List<CellImageURL>) {
|
180
|
-
|
181
|
-
selectedImageView = imageView
|
182
|
-
|
183
|
-
let vc = PhotoPageContainerViewController()
|
184
|
-
|
185
|
-
navigationController?.delegate = vc.transitionController
|
186
|
-
|
187
|
-
vc.transitionController.fromDelegate = self
|
188
|
-
|
189
|
-
vc.transitionController.toDelegate = vc
|
190
|
-
|
191
|
-
vc.delegate = self
|
192
|
-
|
193
|
-
vc.currentIndex = tag
|
194
|
-
|
195
|
-
vc.imageURLs = imageURLs
|
196
|
-
|
197
|
-
navigationController?.pushViewController(vc, animated: true)
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
extension FeedController: ZoomAnimatorDelegate {
|
206
|
-
|
207
|
-
func transitionWillStartWith(zoomAnimator: ZoomAnimator) {
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
func transitionDidEndWith(zoomAnimator: ZoomAnimator) {
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
func referenceImageView(for zoomAnimator: ZoomAnimator) -> UIImageView? {
|
218
|
-
|
219
|
-
return selectedImageView
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
func referenceImageViewFrameInTransitioningView(for zoomAnimator: ZoomAnimator) -> CGRect? {
|
226
|
-
|
227
|
-
view.layoutIfNeeded()
|
228
|
-
|
229
|
-
collectionView.layoutIfNeeded()
|
230
|
-
|
231
|
-
let unconvertedFrame = getFrameFromImageView(for: selectedImageView)
|
232
|
-
|
233
|
-
let imageViewFrame = selectedImageView.convert(unconvertedFrame, to: self.view)
|
234
|
-
|
235
|
-
if imageViewFrame.minY < self.selectedImageView.largeContentImageInsets.top {
|
236
|
-
|
237
|
-
return CGRect(x: imageViewFrame.minX, y: selectedImageView.largeContentImageInsets.top, width: (selectedImageView.image?.size.width)!, height: imageViewFrame.height - (selectedImageView.largeContentImageInsets.top - imageViewFrame.minY))
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
return imageViewFrame
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
}
|
246
|
-
|
247
|
-
```
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
VCのセルです。
|
252
|
-
|
253
|
-
```ここに言語を入力
|
254
|
-
|
255
|
-
class TweetCell: UICollectionViewCell {
|
256
|
-
|
257
|
-
let currentUser = CurrentUser.shared
|
258
|
-
|
259
|
-
var tweets: Tweet = Tweet()
|
260
|
-
|
261
|
-
var replyTweets: ReplyTweet = ReplyTweet()
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
weak var delegate: TweetCellDelegate?
|
266
|
-
|
267
|
-
let captionLabel: ActiveLabel = {
|
268
|
-
|
269
|
-
let label = ActiveLabel()
|
270
|
-
|
271
|
-
return label
|
272
|
-
|
273
|
-
}()
|
274
|
-
|
275
|
-
let infoLabel = UILabel()
|
276
|
-
|
277
|
-
var imageURLs = List<CellImageURL>()
|
278
|
-
|
279
|
-
var imageContainer = UIStackView()
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
override init(frame: CGRect) {
|
284
|
-
|
285
|
-
super.init(frame: frame)
|
286
|
-
|
287
|
-
configure()
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
required init?(coder: NSCoder) {
|
294
|
-
|
295
|
-
fatalError("init(coder:) has not been implemented")
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
override func prepareForReuse() {
|
302
|
-
|
303
|
-
super.prepareForReuse()
|
304
|
-
|
305
|
-
tweets = Tweet()
|
306
|
-
|
307
|
-
replyTweets = ReplyTweet()
|
308
|
-
|
309
|
-
captionLabel.text = ""
|
310
|
-
|
311
|
-
infoLabel.attributedText = nil
|
312
|
-
|
313
|
-
imageURLs = List<CellImageURL>()
|
314
|
-
|
315
|
-
imageContainer.removeFromSuperview()
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
func configure(){
|
322
|
-
|
323
|
-
let stack = UIStackView(arrangedSubviews: [infoLabel, captionLabel])
|
324
|
-
|
325
|
-
stack.axis = .vertical
|
326
|
-
|
327
|
-
stack.spacing = 8
|
328
|
-
|
329
|
-
stack.distribution = .fillProportionally
|
330
|
-
|
331
|
-
addSubview(stack)
|
332
|
-
|
333
|
-
stack.anchor(top: topAnchor, left: leftAnchor, right: rightAnchor, paddingTop: 4, paddingLeft: 12, paddingRight: 12)
|
334
|
-
|
335
|
-
infoLabel.font = UIFont.systemFont(ofSize: 14)
|
336
|
-
|
337
|
-
if !imageURLs.isEmpty {
|
338
|
-
|
339
|
-
let vstack1 = UIStackView()
|
340
|
-
|
341
|
-
vstack1.axis = .vertical
|
342
|
-
|
343
|
-
vstack1.spacing = 2
|
344
|
-
|
345
|
-
vstack1.distribution = .fillEqually
|
346
|
-
|
347
|
-
vstack1.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
348
|
-
|
349
|
-
let vstack2 = UIStackView()
|
350
|
-
|
351
|
-
vstack2.axis = .vertical
|
352
|
-
|
353
|
-
vstack2.spacing = 2
|
354
|
-
|
355
|
-
vstack2.distribution = .fillEqually
|
356
|
-
|
357
|
-
vstack2.isHidden = imageURLs.count == 1
|
358
|
-
|
359
|
-
vstack2.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
360
|
-
|
361
|
-
imageContainer = UIStackView(arrangedSubviews: [vstack1, vstack2])
|
362
|
-
|
363
|
-
imageContainer.axis = .horizontal
|
364
|
-
|
365
|
-
imageContainer.spacing = 2
|
366
|
-
|
367
|
-
imageContainer.distribution = .fillEqually
|
368
|
-
|
369
|
-
addSubview(imageContainer)
|
370
|
-
|
371
|
-
imageContainer.leadingAnchor.constraint(equalTo: captionLabel.leadingAnchor).isActive = true
|
372
|
-
|
373
|
-
imageContainer.topAnchor.constraint(equalTo: captionLabel.bottomAnchor).isActive = true
|
374
|
-
|
375
|
-
imageContainer.anchor(top: captionLabel.bottomAnchor, left: captionLabel.leftAnchor, bottom: bottomAnchor, right: rightAnchor, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, height: 160)
|
376
|
-
|
377
|
-
imageContainer.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
378
|
-
|
379
|
-
imageURLs.enumerated().forEach { index, image in
|
380
|
-
|
381
|
-
let path = fileInDocumentsDirectory(filename: image.imageURL)
|
382
|
-
|
383
|
-
let imageView = UIImageView()
|
384
|
-
|
385
|
-
imageView.isUserInteractionEnabled = true
|
386
|
-
|
387
|
-
imageView.image = UIImage(contentsOfFile: path)
|
388
|
-
|
389
|
-
imageView.tag = index
|
390
|
-
|
391
|
-
if index % 2 == 0 {
|
392
|
-
|
393
|
-
vstack1.addArrangedSubview(imageView)
|
394
|
-
|
395
|
-
} else {
|
396
|
-
|
397
|
-
vstack2.addArrangedSubview(imageView)
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageViewTappedGesture(_:))))
|
402
|
-
|
403
|
-
}
|
404
|
-
|
405
|
-
}
|
406
|
-
|
407
|
-
@objc func imageViewTappedGesture(_ sender: UITapGestureRecognizer){
|
408
|
-
|
409
|
-
let view = sender.view
|
410
|
-
|
411
|
-
let tag = (sender.view?.tag)!
|
412
|
-
|
413
|
-
delegate?.selectedImageView(view! as! UIImageView, tag: tag, imageURLs: imageURLs)
|
414
|
-
|
415
|
-
}
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
```
|