質問編集履歴
3
変更
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
2
変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -68,70 +68,6 @@
|
|
68
68
|
|
69
69
|
import UIKit
|
70
70
|
|
71
|
-
class CustomPresentationController: UIPresentationController {
|
72
|
-
// 呼び出し元のView Controller の上に重ねるビュー(ブラック)
|
73
|
-
var overlayView = UIView()
|
74
|
-
|
75
|
-
override func presentationTransitionWillBegin() {
|
76
|
-
guard let containerView = containerView else {
|
77
|
-
return
|
78
|
-
}
|
79
|
-
|
80
|
-
overlayView.frame = containerView.bounds
|
81
|
-
overlayView.backgroundColor = .black
|
82
|
-
overlayView.alpha = 0.0
|
83
|
-
containerView.insertSubview(overlayView, at: 0)
|
84
|
-
|
85
|
-
presentedViewController.transitionCoordinator?.animate(alongsideTransition: {[weak self] context in
|
86
|
-
self?.overlayView.alpha = 0.7
|
87
|
-
}, completion:nil)
|
88
|
-
}
|
89
|
-
|
90
|
-
override func dismissalTransitionWillBegin() {
|
91
|
-
presentedViewController.transitionCoordinator?.animate(alongsideTransition: {[weak self] context in
|
92
|
-
self?.overlayView.alpha = 0.0
|
93
|
-
}, completion:nil)
|
94
|
-
}
|
95
|
-
|
96
|
-
override func dismissalTransitionDidEnd(_ completed: Bool) {
|
97
|
-
if completed {
|
98
|
-
overlayView.removeFromSuperview()
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
let margin = (x: CGFloat(30), y: CGFloat(220.0))
|
103
|
-
|
104
|
-
override func size(forChildContentContainer container: UIContentContainer, withParentContainerSize parentSize: CGSize) -> CGSize {
|
105
|
-
return CGSize(width: parentSize.width - margin.x, height: parentSize.height - margin.y)
|
106
|
-
}
|
107
|
-
|
108
|
-
override var frameOfPresentedViewInContainerView: CGRect {
|
109
|
-
var presentedViewFrame = CGRect()
|
110
|
-
let containerBounds = containerView!.bounds
|
111
|
-
let childContentSize = size(forChildContentContainer: presentedViewController, withParentContainerSize: containerBounds.size)
|
112
|
-
presentedViewFrame.size = childContentSize
|
113
|
-
presentedViewFrame.origin.x = margin.x / 2.0
|
114
|
-
presentedViewFrame.origin.y = margin.y / 2.0
|
115
|
-
|
116
|
-
return presentedViewFrame
|
117
|
-
}
|
118
|
-
|
119
|
-
override func containerViewWillLayoutSubviews() {
|
120
|
-
overlayView.frame = containerView!.bounds //bounds 境界内
|
121
|
-
presentedView?.frame = frameOfPresentedViewInContainerView
|
122
|
-
presentedView?.layer.cornerRadius = 10
|
123
|
-
presentedView?.clipsToBounds = true
|
124
|
-
}
|
125
|
-
override func containerViewDidLayoutSubviews() {
|
126
|
-
}
|
127
|
-
}
|
128
|
-
|
129
|
-
```
|
130
|
-
|
131
|
-
```ここに言語を入力
|
132
|
-
|
133
|
-
import UIKit
|
134
|
-
|
135
71
|
class FirstViewController: UIViewController, UITextFieldDelegate, UITextViewDelegate {
|
136
72
|
|
137
73
|
override func viewDidLoad() {
|
@@ -318,5 +254,7 @@
|
|
318
254
|
|
319
255
|
}
|
320
256
|
|
257
|
+
```
|
321
258
|
|
322
|
-
|
259
|
+
・追記
|
260
|
+
名称をSecondViewControllerからCollectionViewCellへ変更しました。紛らわしく申し訳ありません。
|
1
変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
FirstViewController(UIViewController)から
|
2
|
-
|
2
|
+
CollectionViewCell(UICollectionViewCell)へ値を渡す方法をコードのみでの実現したいと思っています。
|
3
3
|
|
4
4
|
一連の動作をする4ファイルのコードを記載しました。
|
5
5
|
ご確認いただければ幸いです よろしくお願いします。
|
@@ -22,7 +22,7 @@
|
|
22
22
|
collectionView?.delegate = self
|
23
23
|
collectionView?.dataSource = self
|
24
24
|
|
25
|
-
collectionView?.register(
|
25
|
+
collectionView?.register(CollectionViewCell, forCellWithReuseIdentifier: "cellId")
|
26
26
|
|
27
27
|
}
|
28
28
|
|
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
switch indexPath.item {
|
36
36
|
default:
|
37
|
-
return collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as!
|
37
|
+
return collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! CollectionViewCell
|
38
38
|
|
39
39
|
}
|
40
40
|
}
|
@@ -233,7 +233,7 @@
|
|
233
233
|
@objc func save3(_ sender: UITapGestureRecognizer) {
|
234
234
|
|
235
235
|
//値を渡したい
|
236
|
-
let controller = presentingViewController as!
|
236
|
+
let controller = presentingViewController as! CollectionViewCell
|
237
237
|
|
238
238
|
controller.textFromModal = userName.text!
|
239
239
|
|
@@ -259,7 +259,7 @@
|
|
259
259
|
|
260
260
|
import UIKit
|
261
261
|
|
262
|
-
class
|
262
|
+
class CollectionViewCell: UICollectionViewCell {
|
263
263
|
|
264
264
|
//モーダルビューから受け取るテキスト
|
265
265
|
var textFromModal = "" {
|