質問編集履歴
1
補足
title
CHANGED
File without changes
|
body
CHANGED
@@ -41,4 +41,117 @@
|
|
41
41
|
|
42
42
|
### 補足情報(FW/ツールのバージョンなど)
|
43
43
|
|
44
|
-
xcode9.2
|
44
|
+
xcode9.2
|
45
|
+
|
46
|
+
### 質問の補足
|
47
|
+
|
48
|
+
|
49
|
+
こちらのプログラムは以前回答していただいた方の参考プログラムとなっておりますが、スクロール部分だけ写して誤解させてしまいまして申し訳ございません。
|
50
|
+
|
51
|
+
tableView0.contentOffset.y = scrollView.contentOffset.y
|
52
|
+
tableView1.contentOffset.y = scrollView.contentOffset.y
|
53
|
+
tableView2.contentOffset.y = scrollView.contentOffset.y
|
54
|
+
tableView3.contentOffset.y = scrollView.contentOffset.y
|
55
|
+
の記述を削除するとy軸にある程度スクロールしてから横スクロールすると、下記の画像のようにヘッダー部分のViewが表示されてしまいます。
|
56
|
+
このバグ対策として、上記を入れましたが目的の達成には至りませんでした。
|
57
|
+
|
58
|
+
|
59
|
+
全文はこのようになっております。
|
60
|
+
```
|
61
|
+
|
62
|
+
import UIKit
|
63
|
+
|
64
|
+
class ViewController: UIViewController {
|
65
|
+
|
66
|
+
@IBOutlet weak var horizontalScrollView: UIScrollView!
|
67
|
+
|
68
|
+
@IBOutlet weak var tableView0: UITableView!
|
69
|
+
@IBOutlet weak var tableView1: UITableView!
|
70
|
+
@IBOutlet weak var tableView2: UITableView!
|
71
|
+
@IBOutlet weak var tableView3: UITableView!
|
72
|
+
|
73
|
+
@IBOutlet weak var iconView: UIView!
|
74
|
+
|
75
|
+
@IBOutlet weak var headerTopConstraint: NSLayoutConstraint!
|
76
|
+
@IBOutlet weak var barLeftConstraint: NSLayoutConstraint!
|
77
|
+
|
78
|
+
override func viewDidLoad() {
|
79
|
+
super.viewDidLoad()
|
80
|
+
|
81
|
+
[tableView0,tableView1,tableView2,tableView3].forEach {
|
82
|
+
$0?.delegate = self
|
83
|
+
$0?.dataSource = self
|
84
|
+
$0?.contentInset = UIEdgeInsetsMake(300, 0, 0, 0)
|
85
|
+
}
|
86
|
+
horizontalScrollView.delegate = self
|
87
|
+
|
88
|
+
iconView.clipsToBounds = true
|
89
|
+
iconView.layer.cornerRadius = iconView.frame.width/2
|
90
|
+
}
|
91
|
+
|
92
|
+
override func didReceiveMemoryWarning() {
|
93
|
+
super.didReceiveMemoryWarning()
|
94
|
+
// Dispose of any resources that can be recreated.
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
extension ViewController:UITableViewDelegate,UITableViewDataSource {
|
99
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
100
|
+
return 100
|
101
|
+
}
|
102
|
+
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
103
|
+
return 100
|
104
|
+
}
|
105
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
106
|
+
|
107
|
+
let screenRect0: CGSize = UIScreen.main.bounds.size
|
108
|
+
tableView0.frame = CGRect(x: UIScreen.main.bounds.width * 0.0, y: 0, width: screenRect0.width, height: screenRect0.height)
|
109
|
+
let screenRect1: CGSize = UIScreen.main.bounds.size
|
110
|
+
tableView1.frame = CGRect(x: UIScreen.main.bounds.width * 1.0, y: 0, width: screenRect1.width, height: screenRect1.height)
|
111
|
+
let screenRect2: CGSize = UIScreen.main.bounds.size
|
112
|
+
tableView2.frame = CGRect(x: UIScreen.main.bounds.width * 2.0, y: 0, width: screenRect2.width, height: screenRect2.height)
|
113
|
+
let screenRect3: CGSize = UIScreen.main.bounds.size
|
114
|
+
tableView3.frame = CGRect(x: UIScreen.main.bounds.width * 3.0, y: 0, width: screenRect3.width, height: screenRect3.height)
|
115
|
+
|
116
|
+
let random:Int = Int(arc4random() % 9)
|
117
|
+
let text = ["????","????","????","????","????","????","????","????","????"][random]
|
118
|
+
|
119
|
+
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
|
120
|
+
cell.textLabel?.text = text
|
121
|
+
|
122
|
+
if tableView == tableView0 {
|
123
|
+
cell.contentView.backgroundColor = UIColor(red: 1, green: 0.9, blue: 0.9, alpha: 1)
|
124
|
+
}
|
125
|
+
if tableView == tableView1 {
|
126
|
+
cell.contentView.backgroundColor = UIColor(red: 0.9, green: 1, blue: 0.9, alpha: 1)
|
127
|
+
}
|
128
|
+
if tableView == tableView2 {
|
129
|
+
cell.contentView.backgroundColor = UIColor(red: 1, green: 1, blue: 0.9, alpha: 1)
|
130
|
+
}
|
131
|
+
if tableView == tableView3 {
|
132
|
+
cell.contentView.backgroundColor = UIColor(red: 0.9, green: 0.5, blue: 0.9, alpha: 1)
|
133
|
+
}
|
134
|
+
|
135
|
+
return cell
|
136
|
+
}
|
137
|
+
|
138
|
+
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
139
|
+
|
140
|
+
if (scrollView == self.horizontalScrollView) {
|
141
|
+
barLeftConstraint.constant = scrollView.contentOffset.x/4
|
142
|
+
}
|
143
|
+
else {
|
144
|
+
print(scrollView.contentOffset)
|
145
|
+
headerTopConstraint.constant = max(-(scrollView.contentOffset.y + 300),-300+50)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
}
|
153
|
+
|
154
|
+
```
|
155
|
+
|
156
|
+

|
157
|
+

|