質問編集履歴

2

訂正

2019/10/22 05:41

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- tableViewCellの座標を変した値がios12と13で違うことについて
1
+ tableViewのcontentOffsetを変てスクロールさせ場合のiOS12とiOS13での挙動のについて
test CHANGED
@@ -2,17 +2,33 @@
2
2
 
3
3
 
4
4
 
5
- cellを追加するスペースがない場合は`contentOffset`をいじって`tableView`をセルの高さ分スクロールさせてからセルを追加しい。
5
+ cellを追加するスペースがない場合は`contentOffset`をいじって`tableView`をセルの高さ分スクロールさせてからセルを追加します
6
+
7
+ 連続してセルを追加する場合、iOS12の場合は、contentOffset.yが意図したとおりに増加していきますが、iOS13の場合は1度しか増加せず、よって一度しか意図したとおりにスクロールしません。
8
+
9
+
10
+
11
+ contentOffsetをいじった場合の挙動が違うようですが、プログラムから変更させたcontentOffsetを定着?リフレッシュ??させるようなメソッドなどあるのでしょうか?
12
+
13
+
14
+
15
+ Xcode var 11.1
16
+
17
+ -simulator-
18
+
19
+ iOS 12.1 iPhone Xs Max
20
+
21
+ iOS 13.1 iPhone 11 Pro Max
6
22
 
7
23
 
8
24
 
9
25
  ↓iOS12.1:希望する動きになっている
10
26
 
11
- ![iOS12.1](d34f6455a2f4411a1e0f5eab9af94c0a.gif)
27
+ ![iOS12.1](81c6918d6d410d49b7cfe31c1e20afa6.gif)
12
28
 
13
29
  ↓iOS13.1:スクロールが変…
14
30
 
15
- ![イメージ説明](14fc023306c654030b073e8a94429207.gif)
31
+ ![iOS13.1](6982fd8df7603afc94ad70e64c70bc86.gif)
16
32
 
17
33
 
18
34
 
@@ -30,7 +46,7 @@
30
46
 
31
47
 
32
48
 
33
- var array: [Int] = [1, 2, 3, 4]
49
+ var array: [Int] = [1, 2, 3, 4, 5, 6]
34
50
 
35
51
 
36
52
 
@@ -66,7 +82,7 @@
66
82
 
67
83
  let addCellIndexPath = IndexPath(row: array.count - 1, section: 0)
68
84
 
69
- // 追加するセルの直上のセルのMaxYをself.view系に変換して取得 <= この値がおかしい??
85
+ // 追加するセルの直上のセルのMaxYをself.view系に変換して取得
70
86
 
71
87
  let lastCellMaxY
72
88
 
@@ -74,52 +90,48 @@
74
90
 
75
91
 
76
92
 
77
-      // ログ下に貼っておきます
93
+ // tableViewのmaxY取得
78
-
79
- print("### rectForRow.maxY:", tTableView.rectForRow(at: lastCellIndexPath).maxY)
94
+
80
-
81
- print("### lastCellMaxY:", lastCellMaxY)
95
+ let tTableViewMaxY = tTableView.frame.maxY
82
96
 
83
97
 
84
98
 
85
- // tableViewmaxYを取得
99
+ // addCellを挿入するスペースがない場合処理
86
-
100
+
87
- let tTableViewMaxY = tTableView.frame.maxY
101
+ if lastCellMaxY + 40 > tTableViewMaxY {
88
102
 
89
103
 
90
104
 
91
- // addCell挿入すスペースがない場合の処理
105
+ // スクロール量求め
92
-
106
+
93
- if lastCellMaxY + 40 >= tTableViewMaxY {
107
+ let offsetY: CGFloat = 40 - (tTableViewMaxY - lastCellMaxY) + 0.5
94
108
 
95
109
 
96
110
 
97
- // スクール量求める
111
+ // ロ下に貼っておきます
98
-
112
+
99
- let offsetY: CGFloat = 40 - (tTableViewMaxY - lastCellMaxY) + 0.5
113
+ print("------------------------------------------------")
114
+
115
+ print("### offsetY:", offsetY)
116
+
117
+ print("### before tTableView.contentOffset.y:", tTableView.contentOffset.y)
100
118
 
101
119
 
102
120
 
103
- //print("##############################################")
104
-
105
- //print("tTableViewMaxY:", tTableViewMaxY)
106
-
107
- //print("lastCellMaxY :", lastCellMaxY)
108
-
109
- //print("offsetY :", offsetY)
110
-
111
-
112
-
113
- // スクロール完了後にセルを追加する
121
+ //// スクロール完了後にセルを追加する
114
122
 
115
123
  UIView.animate(withDuration: 0.6, animations: {
116
124
 
117
- self.tTableView.contentOffset.y += offsetY
125
+ self.tTableView.contentOffset.y += offsetY // <= 一度しか加算されない
118
126
 
119
127
  }){(finished) in
120
128
 
129
+ print("### after tTableView.contentOffset.y:", self.tTableView.contentOffset.y)
130
+
121
131
  self.tTableView.insertRows(at: [addCellIndexPath], with: .right)
122
132
 
133
+
134
+
123
135
  }
124
136
 
125
137
  // addCellを挿入するスペースがある場合の処理
@@ -178,93 +190,135 @@
178
190
 
179
191
  /*
180
192
 
181
- ios12.1
182
-
183
- ### rectForRow.maxY: 160.0
184
-
185
- ### lastCellMaxY: 351.0
186
-
187
- ### rectForRow.maxY: 200.0
188
-
189
- ### lastCellMaxY: 391.0
190
-
191
- ### rectForRow.maxY: 240.0
192
-
193
- ### lastCellMaxY: 431.0
194
-
195
- ### rectForRow.maxY: 280.0
196
-
197
- ### lastCellMaxY: 436.33333333333337
198
-
199
- ### rectForRow.maxY: 320.0
200
-
201
- ### lastCellMaxY: 436.3333333333333
202
-
203
- ### rectForRow.maxY: 360.0
204
-
205
- ### lastCellMaxY: 436.3333333333333
206
-
207
- ### rectForRow.maxY: 400.0
208
-
209
- ### lastCellMaxY: 436.33333333333337
210
-
211
- ### rectForRow.maxY: 440.0
212
-
213
- ### lastCellMaxY: 436.33333333333337
214
-
215
- ### rectForRow.maxY: 480.0
216
-
217
- ### lastCellMaxY: 436.33333333333337
218
-
219
- ### rectForRow.maxY: 520.0
220
-
221
- ### lastCellMaxY: 436.3333333333333
222
-
223
-
224
-
225
- iOS 13.1
226
-
227
-
228
-
229
- ### rectForRow.maxY: 160.0
230
-
231
- ### lastCellMaxY: 351.0
232
-
233
- ### rectForRow.maxY: 200.0
234
-
235
- ### lastCellMaxY: 391.0
236
-
237
- ### rectForRow.maxY: 240.0
238
-
239
- ### lastCellMaxY: 431.0
240
-
241
- ### rectForRow.maxY: 280.0
242
-
243
- ### lastCellMaxY: 471.0
244
-
245
- ### rectForRow.maxY: 320.0
246
-
247
- ### lastCellMaxY: 476.33333333333337
248
-
249
- ### rectForRow.maxY: 360.0
250
-
251
- ### lastCellMaxY: 516.3333333333334
252
-
253
- ### rectForRow.maxY: 400.0
254
-
255
- ### lastCellMaxY: 556.3333333333334
256
-
257
- ### rectForRow.maxY: 440.0
258
-
259
- ### lastCellMaxY: 596.3333333333334
260
-
261
- ### rectForRow.maxY: 480.0
262
-
263
- ### lastCellMaxY: 636.3333333333334
264
-
265
- ### rectForRow.maxY: 520.0
266
-
267
- ### lastCellMaxY: 676.3333333333334
193
+ ios12.1 contentOffsetYが増加していく スクロールさせる値のoffsetYは一定。
194
+
195
+ ------------------------------------------------
196
+
197
+ ### offsetY: 35.16666666666663
198
+
199
+ ### before tTableView.contentOffset.y: 0.0
200
+
201
+ ### after tTableView.contentOffset.y: 35.0
202
+
203
+ ------------------------------------------------
204
+
205
+ ### offsetY: 40.5
206
+
207
+ ### before tTableView.contentOffset.y: 34.666666666666664
208
+
209
+ ### after tTableView.contentOffset.y: 75.0
210
+
211
+ ------------------------------------------------
212
+
213
+ ### offsetY: 40.49999999999994
214
+
215
+ ### before tTableView.contentOffset.y: 74.66666666666667
216
+
217
+ ### after tTableView.contentOffset.y: 115.0
218
+
219
+ ------------------------------------------------
220
+
221
+ ### offsetY: 40.49999999999994
222
+
223
+ ### before tTableView.contentOffset.y: 114.66666666666667
224
+
225
+ ### after tTableView.contentOffset.y: 155.0
226
+
227
+ ------------------------------------------------
228
+
229
+ ### offsetY: 40.5
230
+
231
+ ### before tTableView.contentOffset.y: 154.66666666666666
232
+
233
+ ### after tTableView.contentOffset.y: 195.0
234
+
235
+ ------------------------------------------------
236
+
237
+ ### offsetY: 40.5
238
+
239
+ ### before tTableView.contentOffset.y: 194.66666666666666
240
+
241
+ ### after tTableView.contentOffset.y: 235.0
242
+
243
+ ------------------------------------------------
244
+
245
+ ### offsetY: 40.5
246
+
247
+ ### before tTableView.contentOffset.y: 234.66666666666666
248
+
249
+ ### after tTableView.contentOffset.y: 275.0
250
+
251
+ ------------------------------------------------
252
+
253
+ ### offsetY: 40.49999999999994
254
+
255
+ ### before tTableView.contentOffset.y: 274.6666666666667
256
+
257
+ ### after tTableView.contentOffset.y: 315.0
258
+
259
+
260
+
261
+
262
+
263
+ iOS 13.1 contentOffset.yが一度しか増加せず、そのためスクロールさせる値のoffsetYが増加していく。
264
+
265
+ ------------------------------------------------
266
+
267
+ ### offsetY: 35.16666666666663
268
+
269
+ ### before tTableView.contentOffset.y: 0.0
270
+
271
+ ### after tTableView.contentOffset.y: 35.0
272
+
273
+ ------------------------------------------------
274
+
275
+ ### offsetY: 40.5
276
+
277
+ ### before tTableView.contentOffset.y: 34.666666666666664
278
+
279
+ ### after tTableView.contentOffset.y: 34.666666666666664
280
+
281
+ ------------------------------------------------
282
+
283
+ ### offsetY: 80.5
284
+
285
+ ### before tTableView.contentOffset.y: 34.666666666666664
286
+
287
+ ### after tTableView.contentOffset.y: 34.666666666666664
288
+
289
+ ------------------------------------------------
290
+
291
+ ### offsetY: 120.5
292
+
293
+ ### before tTableView.contentOffset.y: 34.666666666666664
294
+
295
+ ### after tTableView.contentOffset.y: 34.666666666666664
296
+
297
+ ------------------------------------------------
298
+
299
+ ### offsetY: 160.5
300
+
301
+ ### before tTableView.contentOffset.y: 34.666666666666664
302
+
303
+ ### after tTableView.contentOffset.y: 34.666666666666664
304
+
305
+ ------------------------------------------------
306
+
307
+ ### offsetY: 200.5
308
+
309
+ ### before tTableView.contentOffset.y: 34.666666666666664
310
+
311
+ ### after tTableView.contentOffset.y: 34.666666666666664
312
+
313
+ ------------------------------------------------
314
+
315
+ ### offsetY: 240.5
316
+
317
+ ### before tTableView.contentOffset.y: 34.666666666666664
318
+
319
+ ### after tTableView.contentOffset.y: 34.666666666666664
320
+
321
+
268
322
 
269
323
 
270
324
 

1

ログ追加

2019/10/22 05:41

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -74,6 +74,8 @@
74
74
 
75
75
 
76
76
 
77
+      // ログを下に貼っておきます
78
+
77
79
  print("### rectForRow.maxY:", tTableView.rectForRow(at: lastCellIndexPath).maxY)
78
80
 
79
81
  print("### lastCellMaxY:", lastCellMaxY)
@@ -174,6 +176,102 @@
174
176
 
175
177
 
176
178
 
179
+ /*
180
+
181
+ ios12.1
182
+
183
+ ### rectForRow.maxY: 160.0
184
+
185
+ ### lastCellMaxY: 351.0
186
+
187
+ ### rectForRow.maxY: 200.0
188
+
189
+ ### lastCellMaxY: 391.0
190
+
191
+ ### rectForRow.maxY: 240.0
192
+
193
+ ### lastCellMaxY: 431.0
194
+
195
+ ### rectForRow.maxY: 280.0
196
+
197
+ ### lastCellMaxY: 436.33333333333337
198
+
199
+ ### rectForRow.maxY: 320.0
200
+
201
+ ### lastCellMaxY: 436.3333333333333
202
+
203
+ ### rectForRow.maxY: 360.0
204
+
205
+ ### lastCellMaxY: 436.3333333333333
206
+
207
+ ### rectForRow.maxY: 400.0
208
+
209
+ ### lastCellMaxY: 436.33333333333337
210
+
211
+ ### rectForRow.maxY: 440.0
212
+
213
+ ### lastCellMaxY: 436.33333333333337
214
+
215
+ ### rectForRow.maxY: 480.0
216
+
217
+ ### lastCellMaxY: 436.33333333333337
218
+
219
+ ### rectForRow.maxY: 520.0
220
+
221
+ ### lastCellMaxY: 436.3333333333333
222
+
223
+
224
+
225
+ iOS 13.1
226
+
227
+
228
+
229
+ ### rectForRow.maxY: 160.0
230
+
231
+ ### lastCellMaxY: 351.0
232
+
233
+ ### rectForRow.maxY: 200.0
234
+
235
+ ### lastCellMaxY: 391.0
236
+
237
+ ### rectForRow.maxY: 240.0
238
+
239
+ ### lastCellMaxY: 431.0
240
+
241
+ ### rectForRow.maxY: 280.0
242
+
243
+ ### lastCellMaxY: 471.0
244
+
245
+ ### rectForRow.maxY: 320.0
246
+
247
+ ### lastCellMaxY: 476.33333333333337
248
+
249
+ ### rectForRow.maxY: 360.0
250
+
251
+ ### lastCellMaxY: 516.3333333333334
252
+
253
+ ### rectForRow.maxY: 400.0
254
+
255
+ ### lastCellMaxY: 556.3333333333334
256
+
257
+ ### rectForRow.maxY: 440.0
258
+
259
+ ### lastCellMaxY: 596.3333333333334
260
+
261
+ ### rectForRow.maxY: 480.0
262
+
263
+ ### lastCellMaxY: 636.3333333333334
264
+
265
+ ### rectForRow.maxY: 520.0
266
+
267
+ ### lastCellMaxY: 676.3333333333334
268
+
269
+
270
+
271
+ */
272
+
273
+
274
+
177
275
 
178
276
 
179
277
  ```