質問するログイン新規登録

質問編集履歴

4

訂正

2018/12/13 02:22

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -120,4 +120,7 @@
120
120
  UIView.animate(withDuration: 0.4, delay: 0.0, animations: { self.contentView.layoutIfNeeded() })
121
121
  }
122
122
  }
123
- ```
123
+ ```
124
+
125
+
126
+ UIViewの背景色はXIBを作る際に、Storyboard上で設定しています。

3

修正

2018/12/13 02:22

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,12 +1,12 @@
1
1
  いつもお世話になります。
2
2
 
3
- `tableView(_:canMoveRowAt:) -> Bool`を`true`にして並び替えをしている際、並び替えするセルを選択するとセルの背景などが透明になてしまうのですが、これを防ぐにはどうしたら良いでしょうか?
3
+ `tableView(_:canMoveRowAt:) -> Bool`を`true`にして並び替えをしている際、並び替えするセルを選択するとセルの上に乗っているUIViewの背景などが透明になり、背後に隠れいるUIView/Labelなどが見えてしまうのですが、これを防ぐにはどうしたら良いでしょうか?
4
4
 
5
5
 
6
6
  ~~並び替えするセルの選択状態が解除される際は、`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)`)は呼び出されないので、並び替えのときは違うメソッドで背景色を透明にしていると思われるのですが、
7
7
  該当するメソッドをご存知でしたら教えてください。
8
8
 
9
- ![イメージ説明](89efc7dea6cd20ab2294d13d17d49c99.gif)
9
+ ![イメージ説明](077924886cea415275b023c957f057c5.gif)
10
10
 
11
11
 
12
12
  ```swift
@@ -46,6 +46,22 @@
46
46
  return cell
47
47
  }
48
48
 
49
+ //
50
+ func tableView(
51
+ _ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
52
+
53
+ if let cell = tTableView.cellForRow(at: indexPath) as? CustomCell {
54
+
55
+ print("# cell:", cell)
56
+
57
+ cell.greenView.backgroundColor = #colorLiteral(red: 0.721568644, green: 0.8862745166, blue: 0.5921568871, alpha: 1)
58
+ cell.blueView.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
59
+
60
+ } else {
61
+ print("### cell:", cell)
62
+ }
63
+ }
64
+
49
65
  // sortable
50
66
  func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
51
67
  return true
@@ -69,9 +85,8 @@
69
85
  func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPaht: IndexPath) -> Bool {
70
86
  return false
71
87
  }
72
-
88
+ }
73
89
 
74
- }
75
90
  ```
76
91
 
77
92
  ```swift
@@ -81,22 +96,28 @@
81
96
 
82
97
  @IBOutlet weak var titleLabel: UILabel!
83
98
 
99
+ @IBOutlet weak var greenView: UIView!
100
+ @IBOutlet weak var blueView: UIView!
101
+
102
+
103
+ @IBOutlet weak var blueViewAppeared: NSLayoutConstraint!
104
+ @IBOutlet weak var blueViewDisappeared: NSLayoutConstraint!
105
+
84
106
  override func awakeFromNib() {
85
107
  super.awakeFromNib()
86
108
  // Initialization code
87
109
  }
88
-
110
+
89
- override func setSelected(_ selected: Bool, animated: Bool) {
111
+ @IBAction func blueViewBtnTapped(_ sender: UIButton) {
90
- super.setSelected(selected, animated: animated)
112
+ blueViewAppeared.isActive = false
91
- print("### setSelected")
113
+ blueViewDisappeared.isActive = true
92
-
114
+ UIView.animate(withDuration: 0.4, delay: 0.0, animations: { self.contentView.layoutIfNeeded() })
93
115
  }
94
116
 
95
- override func setHighlighted(_ highlighted: Bool, animated: Bool) {
117
+ @IBAction func greenViewBtnTapped(_ sender: UIButton) {
96
- super.setHighlighted(highlighted, animated: animated)
97
- print("### setHighlighted")
118
+ blueViewDisappeared.isActive = false
98
-
119
+ blueViewAppeared.isActive = true
120
+ UIView.animate(withDuration: 0.4, delay: 0.0, animations: { self.contentView.layoutIfNeeded() })
99
121
  }
100
-
101
122
  }
102
123
  ```

2

訂正

2018/12/13 02:19

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
  `tableView(_:canMoveRowAt:) -> Bool`を`true`にして並び替えをしている際、並び替えするセルを選択するとセルの背景などが透明になってしまうのですが、これを防ぐにはどうしたら良いでしょうか?
4
4
 
5
5
 
6
- 並び替えするセルの選択状態が解除される際は、`func setSelected(_ selected: Bool, animated: Bool)`と`func setHighlighted(_ highlighted: Bool, animated: Bool)`を通るのですが、並び替えセルが選択状態になる(透明になる)際にはこの2つのメソッドは呼び出されないので、並び替えのときは違うメソッドで背景色を透明にしていると思われるのですが、
6
+ ~~並び替えするセルの選択状態が解除される際は、`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)`)は呼び出されないので、並び替えのときは違うメソッドで背景色を透明にしていると思われるのですが、
7
7
  該当するメソッドをご存知でしたら教えてください。
8
8
 
9
9
  ![イメージ説明](89efc7dea6cd20ab2294d13d17d49c99.gif)

1

追記

2018/12/06 14:49

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -4,4 +4,99 @@
4
4
 
5
5
 
6
6
  並び替えするセルの選択状態が解除される際は、`func setSelected(_ selected: Bool, animated: Bool)`と`func setHighlighted(_ highlighted: Bool, animated: Bool)`を通るのですが、並び替えセルが選択状態になる(透明になる)際にはこの2つのメソッドは呼び出されないので、並び替えのときは違うメソッドで背景色を透明にしていると思われるのですが、
7
- 該当するメソッドをご存知でしたら教えてください。
7
+ 該当するメソッドをご存知でしたら教えてください。
8
+
9
+ ![イメージ説明](89efc7dea6cd20ab2294d13d17d49c99.gif)
10
+
11
+
12
+ ```swift
13
+ import UIKit
14
+
15
+ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
16
+
17
+ @IBOutlet weak var tTableView: UITableView!
18
+
19
+ var tArray = ["AAAAAA", "BBBBBB", "CCCCCC", "DDDDDD"]
20
+
21
+
22
+
23
+ override func viewDidLoad() {
24
+ super.viewDidLoad()
25
+
26
+ let CellNib = UINib.init(nibName: "CustomCell", bundle: Bundle.main)
27
+ tTableView.register(CellNib, forCellReuseIdentifier: "CCell")
28
+
29
+ tTableView.isEditing = true
30
+ }
31
+
32
+
33
+ // numOfCell
34
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
35
+ return tArray.count
36
+ }
37
+
38
+ // generateCell
39
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
40
+ let cell = tableView.dequeueReusableCell(withIdentifier: "CCell", for: indexPath) as! CustomCell
41
+
42
+ //cell.selectionStyle = .none
43
+
44
+ cell.titleLabel.text = tArray[indexPath.row]
45
+
46
+ return cell
47
+ }
48
+
49
+ // sortable
50
+ func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
51
+ return true
52
+ }
53
+
54
+ // editArray
55
+ func tableView(
56
+ _ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
57
+ // レコード配列を編集する
58
+ let targetArray = tArray.remove(at: sourceIndexPath.row)
59
+ tArray.insert(targetArray, at: destinationIndexPath.row)
60
+ }
61
+
62
+ // indicateEditButton
63
+ func tableView(_ tableView: UITableView, editingStyleForRowAt indecxPath: IndexPath)
64
+ -> UITableViewCell.EditingStyle {
65
+ return .none
66
+ }
67
+
68
+ // spaceOfEditIco
69
+ func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPaht: IndexPath) -> Bool {
70
+ return false
71
+ }
72
+
73
+
74
+ }
75
+ ```
76
+
77
+ ```swift
78
+ import UIKit
79
+
80
+ class CustomCell: UITableViewCell {
81
+
82
+ @IBOutlet weak var titleLabel: UILabel!
83
+
84
+ override func awakeFromNib() {
85
+ super.awakeFromNib()
86
+ // Initialization code
87
+ }
88
+
89
+ override func setSelected(_ selected: Bool, animated: Bool) {
90
+ super.setSelected(selected, animated: animated)
91
+ print("### setSelected")
92
+
93
+ }
94
+
95
+ override func setHighlighted(_ highlighted: Bool, animated: Bool) {
96
+ super.setHighlighted(highlighted, animated: animated)
97
+ print("### setHighlighted")
98
+
99
+ }
100
+
101
+ }
102
+ ```