質問編集履歴

1

補足

2018/11/24 05:55

投稿

ottotto
ottotto

スコア22

test CHANGED
File without changes
test CHANGED
@@ -85,3 +85,229 @@
85
85
 
86
86
 
87
87
  xcode9.2
88
+
89
+
90
+
91
+ ### 質問の補足
92
+
93
+
94
+
95
+
96
+
97
+ こちらのプログラムは以前回答していただいた方の参考プログラムとなっておりますが、スクロール部分だけ写して誤解させてしまいまして申し訳ございません。
98
+
99
+
100
+
101
+ tableView0.contentOffset.y = scrollView.contentOffset.y
102
+
103
+ tableView1.contentOffset.y = scrollView.contentOffset.y
104
+
105
+ tableView2.contentOffset.y = scrollView.contentOffset.y
106
+
107
+ tableView3.contentOffset.y = scrollView.contentOffset.y
108
+
109
+ の記述を削除するとy軸にある程度スクロールしてから横スクロールすると、下記の画像のようにヘッダー部分のViewが表示されてしまいます。
110
+
111
+ このバグ対策として、上記を入れましたが目的の達成には至りませんでした。
112
+
113
+
114
+
115
+
116
+
117
+ 全文はこのようになっております。
118
+
119
+ ```
120
+
121
+
122
+
123
+ import UIKit
124
+
125
+
126
+
127
+ class ViewController: UIViewController {
128
+
129
+
130
+
131
+ @IBOutlet weak var horizontalScrollView: UIScrollView!
132
+
133
+
134
+
135
+ @IBOutlet weak var tableView0: UITableView!
136
+
137
+ @IBOutlet weak var tableView1: UITableView!
138
+
139
+ @IBOutlet weak var tableView2: UITableView!
140
+
141
+ @IBOutlet weak var tableView3: UITableView!
142
+
143
+
144
+
145
+ @IBOutlet weak var iconView: UIView!
146
+
147
+
148
+
149
+ @IBOutlet weak var headerTopConstraint: NSLayoutConstraint!
150
+
151
+ @IBOutlet weak var barLeftConstraint: NSLayoutConstraint!
152
+
153
+
154
+
155
+ override func viewDidLoad() {
156
+
157
+ super.viewDidLoad()
158
+
159
+
160
+
161
+ [tableView0,tableView1,tableView2,tableView3].forEach {
162
+
163
+ $0?.delegate = self
164
+
165
+ $0?.dataSource = self
166
+
167
+ $0?.contentInset = UIEdgeInsetsMake(300, 0, 0, 0)
168
+
169
+ }
170
+
171
+ horizontalScrollView.delegate = self
172
+
173
+
174
+
175
+ iconView.clipsToBounds = true
176
+
177
+ iconView.layer.cornerRadius = iconView.frame.width/2
178
+
179
+ }
180
+
181
+
182
+
183
+ override func didReceiveMemoryWarning() {
184
+
185
+ super.didReceiveMemoryWarning()
186
+
187
+ // Dispose of any resources that can be recreated.
188
+
189
+ }
190
+
191
+ }
192
+
193
+
194
+
195
+ extension ViewController:UITableViewDelegate,UITableViewDataSource {
196
+
197
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
198
+
199
+ return 100
200
+
201
+ }
202
+
203
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
204
+
205
+ return 100
206
+
207
+ }
208
+
209
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
210
+
211
+
212
+
213
+ let screenRect0: CGSize = UIScreen.main.bounds.size
214
+
215
+ tableView0.frame = CGRect(x: UIScreen.main.bounds.width * 0.0, y: 0, width: screenRect0.width, height: screenRect0.height)
216
+
217
+ let screenRect1: CGSize = UIScreen.main.bounds.size
218
+
219
+ tableView1.frame = CGRect(x: UIScreen.main.bounds.width * 1.0, y: 0, width: screenRect1.width, height: screenRect1.height)
220
+
221
+ let screenRect2: CGSize = UIScreen.main.bounds.size
222
+
223
+ tableView2.frame = CGRect(x: UIScreen.main.bounds.width * 2.0, y: 0, width: screenRect2.width, height: screenRect2.height)
224
+
225
+ let screenRect3: CGSize = UIScreen.main.bounds.size
226
+
227
+ tableView3.frame = CGRect(x: UIScreen.main.bounds.width * 3.0, y: 0, width: screenRect3.width, height: screenRect3.height)
228
+
229
+
230
+
231
+ let random:Int = Int(arc4random() % 9)
232
+
233
+ let text = ["????","????","????","????","????","????","????","????","????"][random]
234
+
235
+
236
+
237
+ let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
238
+
239
+ cell.textLabel?.text = text
240
+
241
+
242
+
243
+ if tableView == tableView0 {
244
+
245
+ cell.contentView.backgroundColor = UIColor(red: 1, green: 0.9, blue: 0.9, alpha: 1)
246
+
247
+ }
248
+
249
+ if tableView == tableView1 {
250
+
251
+ cell.contentView.backgroundColor = UIColor(red: 0.9, green: 1, blue: 0.9, alpha: 1)
252
+
253
+ }
254
+
255
+ if tableView == tableView2 {
256
+
257
+ cell.contentView.backgroundColor = UIColor(red: 1, green: 1, blue: 0.9, alpha: 1)
258
+
259
+ }
260
+
261
+ if tableView == tableView3 {
262
+
263
+ cell.contentView.backgroundColor = UIColor(red: 0.9, green: 0.5, blue: 0.9, alpha: 1)
264
+
265
+ }
266
+
267
+
268
+
269
+ return cell
270
+
271
+ }
272
+
273
+
274
+
275
+ func scrollViewDidScroll(_ scrollView: UIScrollView) {
276
+
277
+
278
+
279
+ if (scrollView == self.horizontalScrollView) {
280
+
281
+ barLeftConstraint.constant = scrollView.contentOffset.x/4
282
+
283
+ }
284
+
285
+ else {
286
+
287
+ print(scrollView.contentOffset)
288
+
289
+ headerTopConstraint.constant = max(-(scrollView.contentOffset.y + 300),-300+50)
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+ }
298
+
299
+ }
300
+
301
+
302
+
303
+ }
304
+
305
+
306
+
307
+ ```
308
+
309
+
310
+
311
+ ![イメージ説明](d51848bad76ebd7a48718dc2006f6654.png)
312
+
313
+ ![イメージ説明](d3784ca796ba492def68e7f17414e6b2.png)