質問編集履歴

4

訂正

2018/12/13 02:22

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -243,3 +243,9 @@
243
243
  }
244
244
 
245
245
  ```
246
+
247
+
248
+
249
+
250
+
251
+ UIViewの背景色はXIBを作る際に、Storyboard上で設定しています。

3

修正

2018/12/13 02:22

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- `tableView(_:canMoveRowAt:) -> Bool`を`true`にして並び替えをしている際、並び替えするセルを選択するとセルの背景などが透明になてしまうのですが、これを防ぐにはどうしたら良いでしょうか?
5
+ `tableView(_:canMoveRowAt:) -> Bool`を`true`にして並び替えをしている際、並び替えするセルを選択するとセルの上に乗っているUIViewの背景などが透明になり、背後に隠れいるUIView/Labelなどが見えてしまうのですが、これを防ぐにはどうしたら良いでしょうか?
6
6
 
7
7
 
8
8
 
@@ -14,7 +14,7 @@
14
14
 
15
15
 
16
16
 
17
- ![イメージ説明](89efc7dea6cd20ab2294d13d17d49c99.gif)
17
+ ![イメージ説明](077924886cea415275b023c957f057c5.gif)
18
18
 
19
19
 
20
20
 
@@ -94,6 +94,38 @@
94
94
 
95
95
 
96
96
 
97
+ //
98
+
99
+ func tableView(
100
+
101
+ _ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
102
+
103
+
104
+
105
+ if let cell = tTableView.cellForRow(at: indexPath) as? CustomCell {
106
+
107
+
108
+
109
+ print("# cell:", cell)
110
+
111
+
112
+
113
+ cell.greenView.backgroundColor = #colorLiteral(red: 0.721568644, green: 0.8862745166, blue: 0.5921568871, alpha: 1)
114
+
115
+ cell.blueView.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
116
+
117
+
118
+
119
+ } else {
120
+
121
+ print("### cell:", cell)
122
+
123
+ }
124
+
125
+ }
126
+
127
+
128
+
97
129
  // sortable
98
130
 
99
131
  func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
@@ -140,12 +172,10 @@
140
172
 
141
173
  }
142
174
 
143
-
144
-
145
-
146
-
147
175
  }
148
176
 
177
+
178
+
149
179
  ```
150
180
 
151
181
 
@@ -164,6 +194,20 @@
164
194
 
165
195
 
166
196
 
197
+ @IBOutlet weak var greenView: UIView!
198
+
199
+ @IBOutlet weak var blueView: UIView!
200
+
201
+
202
+
203
+
204
+
205
+ @IBOutlet weak var blueViewAppeared: NSLayoutConstraint!
206
+
207
+ @IBOutlet weak var blueViewDisappeared: NSLayoutConstraint!
208
+
209
+
210
+
167
211
  override func awakeFromNib() {
168
212
 
169
213
  super.awakeFromNib()
@@ -172,31 +216,29 @@
172
216
 
173
217
  }
174
218
 
175
-
176
-
219
+
220
+
177
- override func setSelected(_ selected: Bool, animated: Bool) {
221
+ @IBAction func blueViewBtnTapped(_ sender: UIButton) {
178
-
222
+
179
- super.setSelected(selected, animated: animated)
223
+ blueViewAppeared.isActive = false
180
-
224
+
181
- print("### setSelected")
225
+ blueViewDisappeared.isActive = true
226
+
182
-
227
+ UIView.animate(withDuration: 0.4, delay: 0.0, animations: { self.contentView.layoutIfNeeded() })
183
-
184
-
228
+
185
- }
229
+ }
186
-
187
-
188
-
230
+
231
+
232
+
189
- override func setHighlighted(_ highlighted: Bool, animated: Bool) {
233
+ @IBAction func greenViewBtnTapped(_ sender: UIButton) {
190
-
191
- super.setHighlighted(highlighted, animated: animated)
234
+
192
-
193
- print("### setHighlighted")
235
+ blueViewDisappeared.isActive = false
236
+
194
-
237
+ blueViewAppeared.isActive = true
238
+
195
-
239
+ UIView.animate(withDuration: 0.4, delay: 0.0, animations: { self.contentView.layoutIfNeeded() })
196
-
240
+
197
- }
241
+ }
198
-
199
-
200
242
 
201
243
  }
202
244
 

2

訂正

2018/12/13 02:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- 並び替えするセルの選択状態が解除される際は、`func setSelected(_ selected: Bool, animated: Bool)`と`func setHighlighted(_ highlighted: Bool, animated: Bool)`を通るのですが、並び替えセルが選択状態になる(透明になる)際にはこの2つのメソッドは呼び出されないので、並び替えのときは違うメソッドで背景色を透明にしていると思われるのですが、
11
+ ~~並び替えするセルの選択状態が解除される際は、`func setSelected(_ selected: Bool, animated: Bool)`と`func setHighlighted(_ highlighted: Bool, animated: Bool)`を通るのですが~~、並び替えセルが選択状態になる(透明になる)際にはこの2つのメソッド(`func setSelected(_ selected: Bool, animated: Bool)`と`func setHighlighted(_ highlighted: Bool, animated: Bool)`)は呼び出されないので、並び替えのときは違うメソッドで背景色を透明にしていると思われるのですが、
12
12
 
13
13
  該当するメソッドをご存知でしたら教えてください。
14
14
 

1

追記

2018/12/06 14:49

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,193 @@
11
11
  並び替えするセルの選択状態が解除される際は、`func setSelected(_ selected: Bool, animated: Bool)`と`func setHighlighted(_ highlighted: Bool, animated: Bool)`を通るのですが、並び替えセルが選択状態になる(透明になる)際にはこの2つのメソッドは呼び出されないので、並び替えのときは違うメソッドで背景色を透明にしていると思われるのですが、
12
12
 
13
13
  該当するメソッドをご存知でしたら教えてください。
14
+
15
+
16
+
17
+ ![イメージ説明](89efc7dea6cd20ab2294d13d17d49c99.gif)
18
+
19
+
20
+
21
+
22
+
23
+ ```swift
24
+
25
+ import UIKit
26
+
27
+
28
+
29
+ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
30
+
31
+
32
+
33
+ @IBOutlet weak var tTableView: UITableView!
34
+
35
+
36
+
37
+ var tArray = ["AAAAAA", "BBBBBB", "CCCCCC", "DDDDDD"]
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+ override func viewDidLoad() {
46
+
47
+ super.viewDidLoad()
48
+
49
+
50
+
51
+ let CellNib = UINib.init(nibName: "CustomCell", bundle: Bundle.main)
52
+
53
+ tTableView.register(CellNib, forCellReuseIdentifier: "CCell")
54
+
55
+
56
+
57
+ tTableView.isEditing = true
58
+
59
+ }
60
+
61
+
62
+
63
+
64
+
65
+ // numOfCell
66
+
67
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
68
+
69
+ return tArray.count
70
+
71
+ }
72
+
73
+
74
+
75
+ // generateCell
76
+
77
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
78
+
79
+ let cell = tableView.dequeueReusableCell(withIdentifier: "CCell", for: indexPath) as! CustomCell
80
+
81
+
82
+
83
+ //cell.selectionStyle = .none
84
+
85
+
86
+
87
+ cell.titleLabel.text = tArray[indexPath.row]
88
+
89
+
90
+
91
+ return cell
92
+
93
+ }
94
+
95
+
96
+
97
+ // sortable
98
+
99
+ func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
100
+
101
+ return true
102
+
103
+ }
104
+
105
+
106
+
107
+ // editArray
108
+
109
+ func tableView(
110
+
111
+ _ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
112
+
113
+ // レコード配列を編集する
114
+
115
+ let targetArray = tArray.remove(at: sourceIndexPath.row)
116
+
117
+ tArray.insert(targetArray, at: destinationIndexPath.row)
118
+
119
+ }
120
+
121
+
122
+
123
+ // indicateEditButton
124
+
125
+ func tableView(_ tableView: UITableView, editingStyleForRowAt indecxPath: IndexPath)
126
+
127
+ -> UITableViewCell.EditingStyle {
128
+
129
+ return .none
130
+
131
+ }
132
+
133
+
134
+
135
+ // spaceOfEditIco
136
+
137
+ func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPaht: IndexPath) -> Bool {
138
+
139
+ return false
140
+
141
+ }
142
+
143
+
144
+
145
+
146
+
147
+ }
148
+
149
+ ```
150
+
151
+
152
+
153
+ ```swift
154
+
155
+ import UIKit
156
+
157
+
158
+
159
+ class CustomCell: UITableViewCell {
160
+
161
+
162
+
163
+ @IBOutlet weak var titleLabel: UILabel!
164
+
165
+
166
+
167
+ override func awakeFromNib() {
168
+
169
+ super.awakeFromNib()
170
+
171
+ // Initialization code
172
+
173
+ }
174
+
175
+
176
+
177
+ override func setSelected(_ selected: Bool, animated: Bool) {
178
+
179
+ super.setSelected(selected, animated: animated)
180
+
181
+ print("### setSelected")
182
+
183
+
184
+
185
+ }
186
+
187
+
188
+
189
+ override func setHighlighted(_ highlighted: Bool, animated: Bool) {
190
+
191
+ super.setHighlighted(highlighted, animated: animated)
192
+
193
+ print("### setHighlighted")
194
+
195
+
196
+
197
+ }
198
+
199
+
200
+
201
+ }
202
+
203
+ ```