質問編集履歴
1
全体のコードを記載いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -77,4 +77,178 @@
|
|
77
77
|
試したことの三つ目にあるFrame計算の方法にて表示されているタブを非表示にする処理をUIViewControllerBにて行う手もあるのですがそもそもの画面領域が狭まってしまう(タブ領域を使用できない)というのがありますのでなるべく使いたくはありません。
|
78
78
|
どなたかご回答いただけますでしょうか。お願いいたします。
|
79
79
|
|
80
|
-
|
80
|
+
### 追記①
|
81
|
+
TakeOne様にて説明不足の旨ご指摘いただきましたので追記させていただきます。
|
82
|
+
コメント及びご指摘誠にありがとうございます。
|
83
|
+
|
84
|
+
```Swift
|
85
|
+
///MainTabBarController()
|
86
|
+
import Foundation
|
87
|
+
import UIKit
|
88
|
+
|
89
|
+
final class MainTabBarController: UITabBarController {
|
90
|
+
|
91
|
+
override func viewDidLoad() {
|
92
|
+
super.viewDidLoad()
|
93
|
+
setupTab()
|
94
|
+
}
|
95
|
+
|
96
|
+
func setupTab() {
|
97
|
+
/// タブにViewControllerを設定
|
98
|
+
let firstViewController = UIViewControllerA()
|
99
|
+
let UINavigationController_0 = UINavigationController(rootViewController: firstViewController)
|
100
|
+
UINavigationController_0.modalPresentationStyle = .fullScreen
|
101
|
+
UINavigationController_0.tabBarItem = UITabBarItem(title: "tab1", image: .none, tag: 0)
|
102
|
+
|
103
|
+
viewControllers = [UINavigationController_0]
|
104
|
+
}
|
105
|
+
}
|
106
|
+
```
|
107
|
+
|
108
|
+
```Swift
|
109
|
+
///UIViewControllerA()
|
110
|
+
import Foundation
|
111
|
+
import UIKit
|
112
|
+
|
113
|
+
class UIViewControllerA:UIViewController, UIVIEWADelegateProtcol {
|
114
|
+
|
115
|
+
override func viewDidLoad() {
|
116
|
+
let UIVIEWA = UIVIEWA()
|
117
|
+
self.view = UIVIEWA
|
118
|
+
self.view.backgroundColor = .black
|
119
|
+
UIVIEWA.delegate = self
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
func transitionbuttonTappedAction() {
|
124
|
+
let UIVIEWCONTROLLERB = UIViewControllerB()
|
125
|
+
self.navigationController?.pushViewController(UIVIEWCONTROLLERB, animated: true)
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
```Swift
|
132
|
+
///UIVIEWA()
|
133
|
+
|
134
|
+
import Foundation
|
135
|
+
import UIKit
|
136
|
+
|
137
|
+
protocol UIVIEWADelegateProtcol:AnyObject {
|
138
|
+
func transitionbuttonTappedAction()
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
class UIVIEWA:UIView {
|
143
|
+
|
144
|
+
///変数宣言
|
145
|
+
weak var delegate:UIVIEWADelegateProtcol?
|
146
|
+
|
147
|
+
override init(frame: CGRect) {
|
148
|
+
super.init(frame: frame)
|
149
|
+
self.backgroundColor = .black
|
150
|
+
autoLayoutSetUp()
|
151
|
+
autoLayout()
|
152
|
+
}
|
153
|
+
//※初期化処理※
|
154
|
+
required init?(coder: NSCoder) {
|
155
|
+
fatalError("init(coder:) has not been implemented")
|
156
|
+
}
|
157
|
+
|
158
|
+
///遷移ボタン
|
159
|
+
let transitionbutton:UIButton = {
|
160
|
+
let returnButton = UIButton()
|
161
|
+
returnButton.tag = 1
|
162
|
+
returnButton.backgroundColor = .white
|
163
|
+
returnButton.addTarget(self, action: #selector(butttonClicked(_:)), for: UIControl.Event.touchUpInside)
|
164
|
+
return returnButton
|
165
|
+
}()
|
166
|
+
|
167
|
+
///遷移押下された際の挙動
|
168
|
+
@objc func butttonClicked(_ sender: UIButton) {
|
169
|
+
if let delegate = delegate {
|
170
|
+
self.delegate?.transitionbuttonTappedAction()
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
func autoLayoutSetUp() {
|
175
|
+
///各オブジェクトをViewに追加
|
176
|
+
addSubview(transitionbutton)
|
177
|
+
|
178
|
+
///UIオートレイアウトと競合させない処理
|
179
|
+
transitionbutton.translatesAutoresizingMaskIntoConstraints = false
|
180
|
+
}
|
181
|
+
|
182
|
+
func autoLayout() {
|
183
|
+
///適当なレイアウト。押せればOK
|
184
|
+
transitionbutton.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true
|
185
|
+
transitionbutton.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.05).isActive = true
|
186
|
+
transitionbutton.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor, constant: 100).isActive = true
|
187
|
+
transitionbutton.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
|
188
|
+
}
|
189
|
+
}
|
190
|
+
```
|
191
|
+
|
192
|
+
```Swift
|
193
|
+
import Foundation
|
194
|
+
import UIKit
|
195
|
+
|
196
|
+
class UIViewControllerB:UIViewController{
|
197
|
+
|
198
|
+
override func viewDidLoad() {
|
199
|
+
let UIVIEWB = UIVIEWB()
|
200
|
+
self.view = UIVIEWB
|
201
|
+
self.view.backgroundColor = .black
|
202
|
+
}
|
203
|
+
}
|
204
|
+
```
|
205
|
+
|
206
|
+
```Swift
|
207
|
+
import Foundation
|
208
|
+
import UIKit
|
209
|
+
|
210
|
+
class UIVIEWB:UIView {
|
211
|
+
|
212
|
+
override init(frame: CGRect) {
|
213
|
+
super.init(frame: frame)
|
214
|
+
self.backgroundColor = .black
|
215
|
+
autoLayoutSetUp()
|
216
|
+
autoLayout()
|
217
|
+
}
|
218
|
+
//※初期化処理※
|
219
|
+
required init?(coder: NSCoder) {
|
220
|
+
fatalError("init(coder:) has not been implemented")
|
221
|
+
}
|
222
|
+
|
223
|
+
///適当なオブジェクト
|
224
|
+
let tempButton:UIButton = {
|
225
|
+
let returnButton = UIButton()
|
226
|
+
returnButton.backgroundColor = .white
|
227
|
+
return returnButton
|
228
|
+
}()
|
229
|
+
|
230
|
+
func autoLayoutSetUp() {
|
231
|
+
///各オブジェクトをViewに追加
|
232
|
+
addSubview(tempButton)
|
233
|
+
|
234
|
+
///UIオートレイアウトと競合させない処理
|
235
|
+
tempButton.translatesAutoresizingMaskIntoConstraints = false
|
236
|
+
}
|
237
|
+
|
238
|
+
func autoLayout() {
|
239
|
+
_**ここが問題の箇所**_
|
240
|
+
///ここでのtempButtonをUINavigationControllerのバーの下に配置したいのだが、
|
241
|
+
///UINavigationContoller.navigationController?.navigationBar.bottomAnchorの値を持ってくることができない。試したこと一覧は全てダメでした。
|
242
|
+
tempButton.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
|
243
|
+
tempButton.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.05).isActive = true
|
244
|
+
tempButton.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor, constant: 100).isActive = true
|
245
|
+
tempButton.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
|
246
|
+
}
|
247
|
+
}
|
248
|
+
```
|
249
|
+
|
250
|
+
以上になります。問題の箇所はUIViewBのtempButtonのレイアウト部分になります。
|
251
|
+
よろしくお願い申し上げます。
|
252
|
+
|
253
|
+
|
254
|
+
|